all repos — mgba @ 37b2eb05ae944e85bad165fa95da7eaf0e75f7e0

mGBA Game Boy Advance Emulator

GBA: Fix GCC warnings
Jeffrey Pfau jeffrey@endrift.com
Wed, 15 Apr 2015 04:37:24 -0700
commit

37b2eb05ae944e85bad165fa95da7eaf0e75f7e0

parent

688be6948bedf51f1cabf6404b6dec8116e04599

1 files changed, 73 insertions(+), 67 deletions(-)

jump to
M src/gba/sharkport.csrc/gba/sharkport.c

@@ -11,60 +11,63 @@

static const char* const SHARKPORT_HEADER = "SharkPortSave"; bool GBASavedataImportSharkPort(struct GBA* gba, struct VFile* vf) { - char buffer[0x1C]; - if (vf->read(vf, buffer, 4) < 4) { + union { + char c[0x1C]; + int32_t i; + } buffer; + if (vf->read(vf, &buffer.i, 4) < 4) { return false; } - uint32_t size; - LOAD_32(size, 0, buffer); - if (size != strlen(SHARKPORT_HEADER)) { + int32_t size; + LOAD_32(size, 0, &buffer.i); + if (size != (int32_t) strlen(SHARKPORT_HEADER)) { return false; } - if (vf->read(vf, buffer, size) < size) { + if (vf->read(vf, buffer.c, size) < size) { return false; } - if (memcmp(SHARKPORT_HEADER, buffer, size) != 0) { + if (memcmp(SHARKPORT_HEADER, buffer.c, size) != 0) { return false; } - if (vf->read(vf, buffer, 4) < 4) { + if (vf->read(vf, &buffer.i, 4) < 4) { return false; } - LOAD_32(size, 0, buffer); + LOAD_32(size, 0, &buffer.i); if (size != 0x000F0000) { // What is this value? return false; } // Skip first three fields - if (vf->read(vf, buffer, 4) < 4) { + if (vf->read(vf, &buffer.i, 4) < 4) { return false; } - LOAD_32(size, 0, buffer); + LOAD_32(size, 0, &buffer.i); if (vf->seek(vf, size, SEEK_CUR) < 0) { return false; } - if (vf->read(vf, buffer, 4) < 4) { + if (vf->read(vf, &buffer.i, 4) < 4) { return false; } - LOAD_32(size, 0, buffer); + LOAD_32(size, 0, &buffer.i); if (vf->seek(vf, size, SEEK_CUR) < 0) { return false; } - if (vf->read(vf, buffer, 4) < 4) { + if (vf->read(vf, &buffer.i, 4) < 4) { return false; } - LOAD_32(size, 0, buffer); + LOAD_32(size, 0, &buffer.i); if (vf->seek(vf, size, SEEK_CUR) < 0) { return false; } // Read payload - if (vf->read(vf, buffer, 4) < 4) { + if (vf->read(vf, &buffer.i, 4) < 4) { return false; } - LOAD_32(size, 0, buffer); + LOAD_32(size, 0, &buffer.i); if (size < 0x1C || size > SIZE_CART_FLASH1M + 0x1C) { return false; }

@@ -74,31 +77,31 @@ goto cleanup;

} struct GBACartridge* cart = (struct GBACartridge*) gba->memory.rom; - memcpy(buffer, cart->title, 16); - buffer[0x10] = 0; - buffer[0x11] = 0; - buffer[0x12] = cart->checksum; - buffer[0x13] = cart->maker; - buffer[0x14] = 1; - buffer[0x15] = 0; - buffer[0x16] = 0; - buffer[0x17] = 0; - buffer[0x18] = 0; - buffer[0x19] = 0; - buffer[0x1A] = 0; - buffer[0x1B] = 0; - if (memcmp(buffer, payload, 0x1C) != 0) { + memcpy(buffer.c, cart->title, 16); + buffer.c[0x10] = 0; + buffer.c[0x11] = 0; + buffer.c[0x12] = cart->checksum; + buffer.c[0x13] = cart->maker; + buffer.c[0x14] = 1; + buffer.c[0x15] = 0; + buffer.c[0x16] = 0; + buffer.c[0x17] = 0; + buffer.c[0x18] = 0; + buffer.c[0x19] = 0; + buffer.c[0x1A] = 0; + buffer.c[0x1B] = 0; + if (memcmp(buffer.c, payload, 0x1C) != 0) { goto cleanup; } uint32_t checksum; - if (vf->read(vf, buffer, 4) < 4) { + if (vf->read(vf, &buffer.i, 4) < 4) { goto cleanup; } - LOAD_32(checksum, 0, buffer); + LOAD_32(checksum, 0, &buffer.i); uint32_t calcChecksum = 0; - uint32_t i; + int i; for (i = 0; i < size; ++i) { calcChecksum += payload[i] << (calcChecksum % 24); }

@@ -146,10 +149,13 @@ }

bool GBASavedataExportSharkPort(const struct GBA* gba, struct VFile* vf) { - char buffer[0x1C]; - uint32_t size = strlen(SHARKPORT_HEADER); - STORE_32(size, 0, buffer); - if (vf->write(vf, buffer, 4) < 4) { + union { + char c[0x1C]; + int32_t i; + } buffer; + int32_t size = strlen(SHARKPORT_HEADER); + STORE_32(size, 0, &buffer.i); + if (vf->write(vf, &buffer.i, 4) < 4) { return false; } if (vf->write(vf, SHARKPORT_HEADER, size) < size) {

@@ -157,15 +163,15 @@ return false;

} size = 0x000F0000; - STORE_32(size, 0, buffer); - if (vf->write(vf, buffer, 4) < 4) { + STORE_32(size, 0, &buffer.i); + if (vf->write(vf, &buffer.i, 4) < 4) { return false; } const struct GBACartridge* cart = (const struct GBACartridge*) gba->memory.rom; size = sizeof(cart->title); - STORE_32(size, 0, buffer); - if (vf->write(vf, buffer, 4) < 4) { + STORE_32(size, 0, &buffer.i); + if (vf->write(vf, &buffer.i, 4) < 4) { return false; } if (vf->write(vf, cart->title, size) < 4) {

@@ -174,16 +180,16 @@ }

time_t t = time(0); struct tm* tm = localtime(&t); - size = strftime(&buffer[4], sizeof(buffer) - 4, "%m/%d/%Y %I:%M:%S %p", tm); - STORE_32(size, 0, buffer); - if (vf->write(vf, buffer, size + 4) < size + 4) { + size = strftime(&buffer.c[4], sizeof(buffer.c) - 4, "%m/%d/%Y %I:%M:%S %p", tm); + STORE_32(size, 0, &buffer.i); + if (vf->write(vf, buffer.c, size + 4) < size + 4) { return false; } // Last field is blank size = 0; - STORE_32(size, 0, buffer); - if (vf->write(vf, buffer, 4) < 4) { + STORE_32(size, 0, &buffer.i); + if (vf->write(vf, &buffer.i, 4) < 4) { return false; }

@@ -206,33 +212,33 @@ case SAVEDATA_FORCE_NONE:

case SAVEDATA_AUTODETECT: return false; } - STORE_32(size, 0, buffer); - if (vf->write(vf, buffer, 4) < 4) { + STORE_32(size, 0, &buffer.i); + if (vf->write(vf, &buffer.i, 4) < 4) { return false; } size -= 0x1C; - memcpy(buffer, cart->title, 16); - buffer[0x10] = 0; - buffer[0x11] = 0; - buffer[0x12] = cart->checksum; - buffer[0x13] = cart->maker; - buffer[0x14] = 1; - buffer[0x15] = 0; - buffer[0x16] = 0; - buffer[0x17] = 0; - buffer[0x18] = 0; - buffer[0x19] = 0; - buffer[0x1A] = 0; - buffer[0x1B] = 0; - if (vf->write(vf, buffer, 0x1C) < 0x1C) { + memcpy(buffer.c, cart->title, 16); + buffer.c[0x10] = 0; + buffer.c[0x11] = 0; + buffer.c[0x12] = cart->checksum; + buffer.c[0x13] = cart->maker; + buffer.c[0x14] = 1; + buffer.c[0x15] = 0; + buffer.c[0x16] = 0; + buffer.c[0x17] = 0; + buffer.c[0x18] = 0; + buffer.c[0x19] = 0; + buffer.c[0x1A] = 0; + buffer.c[0x1B] = 0; + if (vf->write(vf, buffer.c, 0x1C) < 0x1C) { return false; } uint32_t checksum = 0; - uint32_t i; + int i; for (i = 0; i < 0x1C; ++i) { - checksum += buffer[i] << (checksum % 24); + checksum += buffer.c[i] << (checksum % 24); } if (vf->write(vf, gba->memory.savedata.data, size) < size) {

@@ -243,8 +249,8 @@ for (i = 0; i < size; ++i) {

checksum += ((char) gba->memory.savedata.data[i]) << (checksum % 24); } - STORE_32(checksum, 0, buffer); - if (vf->write(vf, buffer, 4) < 4) { + STORE_32(checksum, 0, &buffer.i); + if (vf->write(vf, &buffer.i, 4) < 4) { return false; }