diff --git a/src/common/fex_mini.cpp b/src/common/fex_mini.cpp index 5c190d6f..578c0976 100644 --- a/src/common/fex_mini.cpp +++ b/src/common/fex_mini.cpp @@ -40,10 +40,11 @@ static const char* get_gzip_size( const char* path, long* eof ) return "Couldn't open file"; unsigned char buf [4]; + int res; if ( fread( buf, 2, 1, file ) > 0 && buf [0] == 0x1F && buf [1] == 0x8B ) { fseek( file, -4, SEEK_END ); - fread( buf, 4, 1, file ); + res = fread( buf, 4, 1, file ); *eof = buf [3] * 0x1000000 + buf [2] * 0x10000 + buf [1] * 0x100 + buf [0]; } else @@ -51,7 +52,7 @@ static const char* get_gzip_size( const char* path, long* eof ) fseek( file, 0, SEEK_END ); *eof = ftell( file ); } - const char* err = (ferror( file ) || feof( file )) ? "Couldn't get file size" : 0; + const char* err = ((res != 1) || ferror( file ) || feof( file )) ? "Couldn't get file size" : 0; fclose( file ); return err; } diff --git a/src/filters/bilinear.cpp b/src/filters/bilinear.cpp index 83ab868f..e2f9d1b7 100644 --- a/src/filters/bilinear.cpp +++ b/src/filters/bilinear.cpp @@ -245,8 +245,7 @@ void Bilinear32(u8 *srcPtr, u32 srcPitch, u8 * /* deltaPtr */, u32 *to_odd = (u32 *)(dstPtr + dstPitch); int from_width = width; - if(width+1 < from_width) - from_width = width+1; + u32 *from = (u32 *)srcPtr; fill_rgb_row_32(from, from_width, rgb_row_cur, width+1); @@ -330,8 +329,7 @@ void BilinearPlus32(u8 *srcPtr, u32 srcPitch, u8 * /* deltaPtr */, u32 *to_odd = (u32 *)(dstPtr + dstPitch); int from_width = width; - if(width+1 < from_width) - from_width = width+1; + u32 *from = (u32 *)srcPtr; fill_rgb_row_32(from, from_width, rgb_row_cur, width+1); diff --git a/src/gb/GB.cpp b/src/gb/GB.cpp index 65e191d1..a759f4fc 100644 --- a/src/gb/GB.cpp +++ b/src/gb/GB.cpp @@ -3852,11 +3852,13 @@ static bool gbReadSaveState(gzFile gzFile) systemDrawScreen(); if(version > GBSAVE_GAME_VERSION_1) + { if( skipSaveGameCheats ) { gbCheatsReadGameSkip(gzFile, version); } else { gbCheatsReadGame(gzFile, version); } + } if (version<11) { diff --git a/src/gb/gbCodes.h b/src/gb/gbCodes.h index 29eb771d..fb9a76ed 100644 --- a/src/gb/gbCodes.h +++ b/src/gb/gbCodes.h @@ -296,7 +296,7 @@ break; case 0x37: // SCF - AF.B.B0 = AF.B.B0 & Z_FLAG | C_FLAG; + AF.B.B0 = (AF.B.B0 & Z_FLAG) | C_FLAG; break; case 0x38: // JR C,NN diff --git a/src/gba/bios.cpp b/src/gba/bios.cpp index 3c80aba8..2f52df49 100644 --- a/src/gba/bios.cpp +++ b/src/gba/bios.cpp @@ -369,7 +369,7 @@ void BIOS_Diff8bitUnFilterWram() source += 4; if(((source & 0xe000000) == 0) || - ((source + ((header >> 8) & 0x1fffff) & 0xe000000) == 0)) + (((source + ((header >> 8) & 0x1fffff)) & 0xe000000) == 0)) return; int len = header >> 8; diff --git a/src/gba/elf.cpp b/src/gba/elf.cpp index 16f25276..3b0cf2f3 100644 --- a/src/gba/elf.cpp +++ b/src/gba/elf.cpp @@ -2782,9 +2782,16 @@ bool elfRead(const char *name, int& siz, FILE *f) long size = ftell(f); elfFileData = (u8 *)malloc(size); fseek(f, 0, SEEK_SET); - fread(elfFileData, 1, size, f); + int res = fread(elfFileData, 1, size, f); fclose(f); + if (res < 0) + { + free(elfFileData); + elfFileData = NULL; + return false; + } + ELFHeader *header = (ELFHeader *)elfFileData; if(READ32LE(&header->magic) != 0x464C457F || diff --git a/src/gba/remote.cpp b/src/gba/remote.cpp index dbf3d306..7c51d707 100644 --- a/src/gba/remote.cpp +++ b/src/gba/remote.cpp @@ -168,10 +168,12 @@ int remotePipeRecv(char *data, int len) bool remotePipeInit() { char dummy; - read(0, &dummy, 1); - if(dummy != '+') { - fprintf(stderr, "ACK not received\n"); - exit(-1); + if (read(0, &dummy, 1) == 1) + { + if(dummy != '+') { + fprintf(stderr, "ACK not received\n"); + exit(-1); + } } return true;