diff --git a/src/asm.cpp b/src/asm.cpp index ed97968f..e05be816 100644 --- a/src/asm.cpp +++ b/src/asm.cpp @@ -15,8 +15,8 @@ int Assemble(unsigned char *output, int addr, char *str) { //unsigned char opcode[3] = { 0,0,0 }; output[0] = output[1] = output[2] = 0; char astr[128],ins[4]; - - if ((!strlen(str)) || (strlen(str) > 0x127)) return 1; + int len = strlen(str); + if ((!len) || (len > 0x127)) return 1; strcpy(astr,str); str_ucase(astr); @@ -211,7 +211,7 @@ int Assemble(unsigned char *output, int addr, char *str) { output[2] = (tmpint >> 8); } else { //Zero Page - if ((output[0] != 0x86) || (output[0] != 0xA2)) return 1; //only STX and LDX Absolute,Y! + if ((output[0] != 0x86) && (output[0] != 0xA2)) return 1; //only STX and LDX Absolute,Y! output[0] |= 0x10; output[1] = (tmpint & 0xFF); } diff --git a/src/cheat.cpp b/src/cheat.cpp index d5c20887..d27310a8 100644 --- a/src/cheat.cpp +++ b/src/cheat.cpp @@ -608,7 +608,7 @@ int FCEUI_SetCheat(uint32 which, const char *name, int32 a, int32 v, int compare { char *t; - if((t=(char *)realloc(next->name,strlen(name+1)))) + if((t=(char *)realloc(next->name,strlen(name)+1))) { next->name=t; strcpy(next->name,name); diff --git a/src/debug.cpp b/src/debug.cpp index 037af069..8d69f1d1 100644 --- a/src/debug.cpp +++ b/src/debug.cpp @@ -228,7 +228,7 @@ int getBank(int offs) } int GetNesFileAddress(int A){ - unsigned int result; + int result; if((A < 0x8000) || (A > 0xFFFF))return -1; result = &Page[A>>11][A]-PRGptr[0]; if((result > PRGsize[0]) || (result < 0))return -1; diff --git a/src/drivers/win/debugger.cpp b/src/drivers/win/debugger.cpp index 0a889e62..e175ea64 100644 --- a/src/drivers/win/debugger.cpp +++ b/src/drivers/win/debugger.cpp @@ -478,7 +478,7 @@ int *GetEditHexData(HWND hwndDlg, int id){ int i,j, k; GetDlgItemText(hwndDlg,id,str,60); - memset(data,0,30*sizeof(int)); + memset(data,0,31*sizeof(int)); j=0; for(i = 0;i < 60;i++){ if(str[i] == 0)break; diff --git a/src/drivers/win/gui.cpp b/src/drivers/win/gui.cpp index 6ffea5ed..ab3a158c 100644 --- a/src/drivers/win/gui.cpp +++ b/src/drivers/win/gui.cpp @@ -11,30 +11,30 @@ void CenterWindow(HWND hwndDlg) { //TODO: This function should probably moved into the generic Win32 window file - //move the window relative to its parent - HWND hwndParent = GetParent(hwndDlg); + //move the window relative to its parent + HWND hwndParent = GetParent(hwndDlg); RECT rect; RECT rectP; - GetWindowRect(hwndDlg, &rect); - GetWindowRect(hwndParent, &rectP); + GetWindowRect(hwndDlg, &rect); + GetWindowRect(hwndParent, &rectP); - unsigned int width = rect.right - rect.left; - unsigned height = rect.bottom - rect.top; + int width = rect.right - rect.left; + int height = rect.bottom - rect.top; - unsigned x = ((rectP.right-rectP.left) - width) / 2 + rectP.left; - unsigned y = ((rectP.bottom-rectP.top) - height) / 2 + rectP.top; + int x = ((rectP.right-rectP.left) - width) / 2 + rectP.left; + int y = ((rectP.bottom-rectP.top) - height) / 2 + rectP.top; - unsigned int screenwidth = GetSystemMetrics(SM_CXSCREEN); - unsigned int screenheight = GetSystemMetrics(SM_CYSCREEN); + int screenwidth = GetSystemMetrics(SM_CXSCREEN); + int screenheight = GetSystemMetrics(SM_CYSCREEN); - //make sure that the dialog box never moves outside of the screen - if(x < 0) x = 0; - if(y < 0) y = 0; - if(x + width > screenwidth) x = screenwidth - width; - if(y + height > screenheight) y = screenheight - height; + //make sure that the dialog box never moves outside of the screen + if(x < 0) x = 0; + if(y < 0) y = 0; + if(x + width > screenwidth) x = screenwidth - width; + if(y + height > screenheight) y = screenheight - height; - MoveWindow(hwndDlg, x, y, width, height, FALSE); + MoveWindow(hwndDlg, x, y, width, height, FALSE); } /** diff --git a/src/drivers/win/input.cpp b/src/drivers/win/input.cpp index ddcec408..e76696ce 100644 --- a/src/drivers/win/input.cpp +++ b/src/drivers/win/input.cpp @@ -1691,22 +1691,21 @@ static void PresetImport(int preset) { //Save the directory if(ofn.nFileOffset < 1024) - if(ofn.nFileOffset < 1024) - { - free(InputPresetDir); - InputPresetDir=(char*)malloc(strlen(ofn.lpstrFile)+1); - strcpy(InputPresetDir,ofn.lpstrFile); - InputPresetDir[ofn.nFileOffset]=0; - } + { + free(InputPresetDir); + InputPresetDir=(char*)malloc(strlen(ofn.lpstrFile)+1); + strcpy(InputPresetDir,ofn.lpstrFile); + InputPresetDir[ofn.nFileOffset]=0; + } - FILE *fp=FCEUD_UTF8fopen(nameo,"r"); - switch(preset) - { - case 1: fread(GamePadPreset1,1,sizeof(GamePadPreset1),fp); break; - case 2: fread(GamePadPreset2,1,sizeof(GamePadPreset2),fp); break; - case 3: fread(GamePadPreset3,1,sizeof(GamePadPreset3),fp); break; - } - fclose(fp); + FILE *fp=FCEUD_UTF8fopen(nameo,"r"); + switch(preset) + { + case 1: fread(GamePadPreset1,1,sizeof(GamePadPreset1),fp); break; + case 2: fread(GamePadPreset2,1,sizeof(GamePadPreset2),fp); break; + case 3: fread(GamePadPreset3,1,sizeof(GamePadPreset3),fp); break; + } + fclose(fp); } } diff --git a/src/drivers/win/main.cpp b/src/drivers/win/main.cpp index 9d82a706..091c0219 100644 --- a/src/drivers/win/main.cpp +++ b/src/drivers/win/main.cpp @@ -608,7 +608,7 @@ int main(int argc,char *argv[]) SetThreadAffinityMask(GetCurrentThread(),1); - printf("%08x",opsize); + //printf("%08x",opsize); //AGAIN?! char *t; @@ -832,7 +832,7 @@ doloopy: if(closeGame) { FCEUI_CloseGame(); - GameInfo = 0; + GameInfo = NULL; } } diff --git a/src/drivers/win/memview.cpp b/src/drivers/win/memview.cpp index 3b53622c..13fc61bc 100644 --- a/src/drivers/win/memview.cpp +++ b/src/drivers/win/memview.cpp @@ -683,7 +683,7 @@ void UnfreezeAllRam() { // would be added by the freeze command. Manual unfreeze should let them // make that mistake once or twice, in case they like it that way. FCEUI_GetCheat(i,&Cname,&Caddr,NULL,NULL,NULL,&Ctype); - if ((Cname[0] == '\0') && (((Caddr >= 0) && (Caddr < 0x2000)) || ((Caddr >= 0x6000) && (Caddr < 0x8000))) && (Ctype == 1)) { + if ((Cname[0] == '\0') && ((Caddr < 0x2000) || ((Caddr >= 0x6000) && (Caddr < 0x8000))) && (Ctype == 1)) { // Already Added, so consider it a success FreezeRam(Caddr,-1,1); diff --git a/src/drivers/win/memwatch.cpp b/src/drivers/win/memwatch.cpp index 03be3374..5115f39b 100644 --- a/src/drivers/win/memwatch.cpp +++ b/src/drivers/win/memwatch.cpp @@ -708,7 +708,7 @@ static BOOL CALLBACK MemWatchCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARA switch(uMsg) { case WM_ENTERMENULOOP: - EnableMenuItem(memwmenu,MEMW_FILE_SAVE,MF_BYCOMMAND | fileChanged ? MF_ENABLED:MF_GRAYED); + EnableMenuItem(memwmenu,MEMW_FILE_SAVE,MF_BYCOMMAND | (fileChanged ? MF_ENABLED : MF_GRAYED)); break; case WM_MOVE: { if (!IsIconic(hwndDlg)) { diff --git a/src/drivers/win/monitor.cpp b/src/drivers/win/monitor.cpp index 9947395f..d5645a6f 100644 --- a/src/drivers/win/monitor.cpp +++ b/src/drivers/win/monitor.cpp @@ -114,7 +114,7 @@ BOOL updateResults(HWND hwndDlg, int rule) if ( chosen_rules[i] == RULE_EXACT || chosen_rules[i] == RULE_EXACT_NOT ) { - SendDlgItemMessage( hwndDlg, RULE_INPUT_1 + i, WM_GETTEXT, sizeof(buff - 1), (LPARAM) input_buff ); + SendDlgItemMessage( hwndDlg, RULE_INPUT_1 + i, WM_GETTEXT, sizeof(buff) - 1, (LPARAM) input_buff ); unsigned int len = strlen(input_buff); diff --git a/src/drivers/win/ram_search.cpp b/src/drivers/win/ram_search.cpp index 392c5923..9b6ffe21 100644 --- a/src/drivers/win/ram_search.cpp +++ b/src/drivers/win/ram_search.cpp @@ -50,7 +50,7 @@ bool IsHardwareAddressValid(HWAddressType address) if (!GameInfo) return false; - if ((address >= 0x0000 && address <= 0x07ff) || (address >= 0x6000 && address <= 0x7FFF)) + if ((address <= 0x07ff) || (address >= 0x6000 && address <= 0x7FFF)) return true; else return false; @@ -874,10 +874,10 @@ bool Set_RS_Val() appliedSize = 'w', appliedSign = 'u'; if(rs_c == 'a') appliedSize = 'd', appliedSign = 'u'; - if((appliedSize == 'b' && appliedSize == 's' && (rs_param < -128 || rs_param > 127)) || - (appliedSize == 'b' && appliedSize != 's' && (rs_param < 0 || rs_param > 255)) || - (appliedSize == 'w' && appliedSize == 's' && (rs_param < -32768 || rs_param > 32767)) || - (appliedSize == 'w' && appliedSize != 's' && (rs_param < 0 || rs_param > 65535))) + if((appliedSize == 'b' && appliedSign == 's' && (rs_param < -128 || rs_param > 127)) || + (appliedSize == 'b' && appliedSign != 's' && (rs_param < 0 || rs_param > 255)) || + (appliedSize == 'w' && appliedSign == 's' && (rs_param < -32768 || rs_param > 32767)) || + (appliedSize == 'w' && appliedSign != 's' && (rs_param < 0 || rs_param > 65535))) return false; } diff --git a/src/drivers/win/ramwatch.h b/src/drivers/win/ramwatch.h index bb368477..41700089 100644 --- a/src/drivers/win/ramwatch.h +++ b/src/drivers/win/ramwatch.h @@ -21,11 +21,11 @@ extern bool RWfileChanged; struct AddressWatcher { unsigned int Address; // hardware address - char Size; //'d' = 4 bytes, 'w' = 2 bytes, 'b' = 1 byte, and 'S' means it's a separator. - char Type;//'s' = signed integer, 'u' = unsigned, 'h' = hex, 'S' = separator + unsigned int CurValue; char* comment; // NULL means no comment, non-NULL means allocated comment bool WrongEndian; - unsigned int CurValue; + char Size; //'d' = 4 bytes, 'w' = 2 bytes, 'b' = 1 byte, and 'S' means it's a separator. + char Type;//'s' = signed integer, 'u' = unsigned, 'h' = hex, 'S' = separator }; #define MAX_WATCH_COUNT 256 extern AddressWatcher rswatches[MAX_WATCH_COUNT]; diff --git a/src/drivers/win/replay.cpp b/src/drivers/win/replay.cpp index 38b3f028..fc561436 100644 --- a/src/drivers/win/replay.cpp +++ b/src/drivers/win/replay.cpp @@ -965,7 +965,7 @@ void FCEUD_MovieRecordTo() if(loadStateFailed) { char str [1024]; - sprintf(str, "Failed to load save state \"%s\".\nRecording from current state instead...", p.szSavestateFilename); + sprintf(str, "Failed to load save state \"%s\".\nRecording from current state instead...", p.szSavestateFilename.c_str()); FCEUD_PrintError(str); } } diff --git a/src/drivers/win/taseditor/selection.cpp b/src/drivers/win/taseditor/selection.cpp index bf2341b6..ee6a550c 100644 --- a/src/drivers/win/taseditor/selection.cpp +++ b/src/drivers/win/taseditor/selection.cpp @@ -333,7 +333,6 @@ void SELECTION::saveSelection(SelectionFrames& selection, EMUFILE *os) bool SELECTION::loadSelection(SelectionFrames& selection, EMUFILE *is) { int temp_int, temp_size; - selection.clear(); if (!read32le(&temp_size, is)) return true; selection.clear(); for(; temp_size > 0; temp_size--) diff --git a/src/drivers/win/texthook.cpp b/src/drivers/win/texthook.cpp index 84891cc9..fdc919c1 100644 --- a/src/drivers/win/texthook.cpp +++ b/src/drivers/win/texthook.cpp @@ -345,8 +345,8 @@ void TextHookerUnloadTableFile(){ //clear the selections hash holder if ( hashholder != NULL ) { - memset( hashholder, 0, sizeof( hashholder ) ); free( hashholder ); + hashholder = NULL; } //if there are words... @@ -739,7 +739,7 @@ int TextHookerSaveTableFile(){ //write the selection hashes to the file for ( i = 0; i < numselections; i++ ) { - memset( str, 0, 365 ); //init str + memset( str, 0, sizeof( str ) ); //init str SendDlgItemMessage(hTextHooker,109,CB_GETLBTEXT,i,(LPARAM)(LPTSTR)str); //get the selection name fputs( str, FP ); //write the name fputs( "=", FP ); //write the = @@ -797,8 +797,8 @@ BOOL CALLBACK TextHookerCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa int si; int saveFileErrorCheck = 0; //used to display error message that may have arised from saving a file - memset( str, 0, sizeof( char ) * 2048 ); - memset( bufferstr, 0, sizeof( char ) * 10240 ); + memset( str, 0, sizeof( str ) ); + memset( bufferstr, 0, sizeof( bufferstr )); switch(uMsg) { case WM_INITDIALOG: @@ -854,7 +854,7 @@ BOOL CALLBACK TextHookerCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa else sprintf( str, "Table is not Loaded!\r\nError on line: %d", result ); //store the current text into the buffer - GetDlgItemText(hwndDlg,102,bufferstr,10240); + GetDlgItemText(hwndDlg,102,bufferstr,sizeof( bufferstr )); strcat( bufferstr, "\r\n" ); //add a newline strcat( bufferstr, str ); //add the status message to the buffer SetDlgItemText(hwndDlg,102,bufferstr); //display the buffer @@ -995,7 +995,7 @@ BOOL CALLBACK TextHookerCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa } //store the current text into the buffer - GetDlgItemText(hwndDlg,102,bufferstr,10240); + GetDlgItemText(hwndDlg,102,bufferstr,sizeof( bufferstr )); strcat( bufferstr, "\r\n" ); //add a newline strcat( bufferstr, str ); //add the status message to the buffer SetDlgItemText(hwndDlg,102,bufferstr); //display the buffer @@ -1103,7 +1103,7 @@ BOOL CALLBACK TextHookerCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa current = words->next; //get the first word while ( current != NULL ) { //while there's still words to check found = strstr( str, current->ja ); //search the buffer for the word - memset( bufferstrtemp, 0, sizeof( str ) ); //init the temp buffer + memset( bufferstrtemp, 0, sizeof( bufferstrtemp ) ); //init the temp buffer if ( found ) { //if we found it, replace it //add a null byte after the first half strcpy( (char*)found, "\0" ); @@ -1130,7 +1130,7 @@ BOOL CALLBACK TextHookerCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa //store the current text into the buffer - GetDlgItemText(hwndDlg,102,bufferstr,10240); + GetDlgItemText(hwndDlg,102,bufferstr,sizeof( bufferstr )); strcat( bufferstr, "\r\n" ); //add a newline strcat( bufferstr, str ); //add the hooked text to the buffer SetDlgItemText(hwndDlg,102,bufferstr); //display the buffer @@ -1175,7 +1175,7 @@ BOOL CALLBACK TextHookerCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa if ( !found ) { found = strstr( str, "\r\n" ); //and also for newlines } - memset( bufferstrtemp, 0, sizeof( str ) ); //init the temp buffer + memset( bufferstrtemp, 0, sizeof( bufferstrtemp ) ); //init the temp buffer if ( found ) { //found something to replace! //add a null byte after the first half strcpy( (char*)found, "\0" ); diff --git a/src/drivers/win/window.cpp b/src/drivers/win/window.cpp index 5bcabede..2ecde9ca 100644 --- a/src/drivers/win/window.cpp +++ b/src/drivers/win/window.cpp @@ -462,7 +462,7 @@ void UpdateContextMenuItems(HMENU context, int whichContext) string undoSavestate = "Undo savestate"; string redoSavestate = "Redo savestate"; - CheckMenuItem(context,ID_CONTEXT_FULLSAVESTATES,MF_BYCOMMAND | fullSaveStateLoads?MF_CHECKED:MF_UNCHECKED); + CheckMenuItem(context,ID_CONTEXT_FULLSAVESTATES,MF_BYCOMMAND | (fullSaveStateLoads ? MF_CHECKED : MF_UNCHECKED)); //Undo Loadstate if (CheckBackupSaveStateExist() && (undoLS || redoLS)) @@ -1005,8 +1005,8 @@ void CloseGame() { FCEUI_CloseGame(); KillMemView(); - updateGameDependentMenus(GameInfo != 0); - updateGameDependentMenusDebugger(GameInfo != 0); + updateGameDependentMenus(1); + updateGameDependentMenusDebugger(1); SetMainWindowText(); } } @@ -1067,7 +1067,7 @@ bool ALoad(char *nameo, char* innerFilename) updateGameDependentMenus(GameInfo != 0); updateGameDependentMenusDebugger(GameInfo != 0); - EmulationPaused = oldPaused; + EmulationPaused = oldPaused; return true; } diff --git a/src/fceu.cpp b/src/fceu.cpp index 3ff6572c..dfc15a46 100644 --- a/src/fceu.cpp +++ b/src/fceu.cpp @@ -89,7 +89,7 @@ FCEUGI::FCEUGI() : filename(0) , archiveFilename(0) { - printf("%08x",opsize); + //printf("%08x",opsize); // WTF?! } FCEUGI::~FCEUGI() @@ -177,7 +177,7 @@ static void FCEU_CloseGame(void) CloseGenie(); delete GameInfo; - GameInfo = 0; + GameInfo = NULL; currFrameCounter = 0; @@ -196,7 +196,7 @@ static void FCEU_CloseGame(void) uint64 timestampbase; -FCEUGI *GameInfo = 0; +FCEUGI *GameInfo = NULL; void (*GameInterface)(GI h); void (*GameStateRestore)(int version); diff --git a/src/fds.cpp b/src/fds.cpp index 84404560..873fb498 100644 --- a/src/fds.cpp +++ b/src/fds.cpp @@ -81,7 +81,7 @@ static uint8 *diskdata[8]={0,0,0,0,0,0,0,0}; static int TotalSides; //mbg merge 7/17/06 - unsignedectomy static uint8 DiskWritten=0; /* Set to 1 if disk was written to. */ static uint8 writeskip; -static uint32 DiskPtr; +static int32 DiskPtr; static int32 DiskSeekIRQ; static uint8 SelectDisk,InDisk; diff --git a/src/ines.cpp b/src/ines.cpp index 33101f8a..8f4264fd 100644 --- a/src/ines.cpp +++ b/src/ines.cpp @@ -881,12 +881,10 @@ int iNesSaveAs(char* name) FILE *fp; if(GameInfo->type != GIT_CART)return 0; - if(GameInterface!=iNESGI)return 0; + if(GameInterface != iNESGI)return 0; fp = fopen(name,"wb"); - int x = 0; - if (!fp) - int x = 1; + if(fwrite(&head,1,16,fp)!=16) { fclose(fp); diff --git a/src/utils/xstring.cpp b/src/utils/xstring.cpp index a65a7d5a..d5f40b5b 100644 --- a/src/utils/xstring.cpp +++ b/src/utils/xstring.cpp @@ -62,24 +62,20 @@ int str_ltrim(char *str, int flags) { unsigned int i=0; //mbg merge 7/17/06 changed to unsigned int while (str[0]) { - if ((str[0] != ' ') || (str[0] != '\t') || (str[0] != '\r') || (str[0] != '\n')) break; - if ((flags & STRIP_SP) && (str[0] == ' ')) { i++; strcpy(str,str+1); - } - if ((flags & STRIP_TAB) && (str[0] == '\t')) { + } else if ((flags & STRIP_TAB) && (str[0] == '\t')) { i++; strcpy(str,str+1); - } - if ((flags & STRIP_CR) && (str[0] == '\r')) { + } else if ((flags & STRIP_CR) && (str[0] == '\r')) { i++; strcpy(str,str+1); - } - if ((flags & STRIP_LF) && (str[0] == '\n')) { + } else if ((flags & STRIP_LF) && (str[0] == '\n')) { i++; strcpy(str,str+1); - } + } else + break; } return i; } @@ -90,30 +86,23 @@ int str_ltrim(char *str, int flags) { ///Removes whitespace from right side of string, depending on the flags set (See STRIP_x definitions in xstring.h) ///Returns number of characters removed int str_rtrim(char *str, int flags) { - unsigned int i=0; //mbg merge 7/17/06 changed to unsigned int - - while (strlen(str)) { - if ((str[strlen(str)-1] != ' ') || - (str[strlen(str)-1] != '\t') || - (str[strlen(str)-1] != '\r') || - (str[strlen(str)-1] != '\n')) break; + unsigned int i=0, strl; //mbg merge 7/17/06 changed to unsigned int + while (strl = strlen(str)) { if ((flags & STRIP_SP) && (str[0] == ' ')) { i++; - str[strlen(str)-1] = 0; - } - if ((flags & STRIP_TAB) && (str[0] == '\t')) { + str[str] = 0; + } else if ((flags & STRIP_TAB) && (str[0] == '\t')) { i++; - str[strlen(str)-1] = 0; - } - if ((flags & STRIP_CR) && (str[0] == '\r')) { + str[strl] = 0; + } else if ((flags & STRIP_CR) && (str[0] == '\r')) { i++; - str[strlen(str)-1] = 0; - } - if ((flags & STRIP_LF) && (str[0] == '\n')) { + str[strl] = 0; + } else if ((flags & STRIP_LF) && (str[0] == '\n')) { i++; - str[strlen(str)-1] = 0; - } + str[strl] = 0; + } else + break; } return i; } @@ -441,7 +430,7 @@ void splitpath(const char* path, char* drv, char* dir, char* name, char* ext) *name = '\0'; } else for(s=p; s