From 37b2eb05ae944e85bad165fa95da7eaf0e75f7e0 Mon Sep 17 00:00:00 2001 From: Jeffrey Pfau Date: Wed, 15 Apr 2015 04:37:24 -0700 Subject: [PATCH] GBA: Fix GCC warnings --- src/gba/sharkport.c | 140 +++++++++++++++++++++++--------------------- 1 file changed, 73 insertions(+), 67 deletions(-) diff --git a/src/gba/sharkport.c b/src/gba/sharkport.c index be6f1561e..4a6f5ded2 100644 --- a/src/gba/sharkport.c +++ b/src/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 @@ bool GBASavedataImportSharkPort(struct GBA* gba, struct VFile* vf) { } 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 @@ cleanup: 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 @@ bool GBASavedataExportSharkPort(const struct GBA* gba, struct VFile* vf) { } 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 @@ bool GBASavedataExportSharkPort(const struct GBA* gba, struct VFile* vf) { 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 @@ bool GBASavedataExportSharkPort(const struct GBA* gba, struct VFile* vf) { 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 @@ bool GBASavedataExportSharkPort(const struct GBA* gba, struct VFile* vf) { 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; }