From 96cba27965c0e5d3f568ec9e2d7e5fade3e90fbd Mon Sep 17 00:00:00 2001 From: Matthew Budd Date: Mon, 15 Jun 2020 22:09:12 -0400 Subject: [PATCH] Resolved cppcheck warnings in cheats.cpp. --- src/drivers/win/cheat.cpp | 14 +++++++------- src/drivers/win/ramwatch.h | 8 +++++++- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/drivers/win/cheat.cpp b/src/drivers/win/cheat.cpp index 0fdc721d..51420385 100644 --- a/src/drivers/win/cheat.cpp +++ b/src/drivers/win/cheat.cpp @@ -538,7 +538,7 @@ INT_PTR CALLBACK CheatConsoleCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARA break; case CHEAT_CONTEXT_POSSI_ADDTOMEMORYWATCH: { - char addr[16] = { 0 }; + char addr[32] = { 0 }; int sel = SendDlgItemMessage(hwndDlg, IDC_CHEAT_LIST_POSSIBILITIES, LVM_GETSELECTIONMARK, 0, 0); if (sel != -1) { @@ -816,9 +816,9 @@ INT_PTR CALLBACK CheatConsoleCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARA if (strchr(buf, ':')) { if (strchr(buf, '?')) - sscanf(buf, "%X:%X?%X", &a, &c, &v); + sscanf(buf, "%X:%X?%X", (unsigned int*)&a, (unsigned int*)&c, (unsigned int*)&v); else - sscanf(buf, "%X:%X", &a, &v); + sscanf(buf, "%X:%X", (unsigned int*)&a, (unsigned int*)&v); } SetDlgItemText(hwndDlg, IDC_CHEAT_ADDR, (LPCSTR)(a == -1 ? "" : U16ToStr(a))); @@ -978,7 +978,7 @@ INT_PTR CALLBACK CheatConsoleCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARA break; case NM_DBLCLK: { - char addr[16]; + char addr[32]; sprintf(addr, "%04X", possiList[((NMITEMACTIVATE*)lParam)->iItem].addr); AddMemWatch(addr); } @@ -1035,19 +1035,19 @@ void UpdateCheatListGroupBoxUI() char temp[64]; if (FrozenAddressCount < 256) { - sprintf(temp, "Active Cheats %d", FrozenAddressCount); + sprintf(temp, "Active Cheats %u", FrozenAddressCount); EnableWindow(GetDlgItem(hCheat, IDC_BTN_CHEAT_ADD), TRUE); EnableWindow(GetDlgItem(hCheat, IDC_BTN_CHEAT_ADDFROMFILE), TRUE); } else if (FrozenAddressCount == 256) { - sprintf(temp, "Active Cheats %d (Max Limit)", FrozenAddressCount); + sprintf(temp, "Active Cheats %u (Max Limit)", FrozenAddressCount); EnableWindow(GetDlgItem(hCheat, IDC_BTN_CHEAT_ADD), FALSE); EnableWindow(GetDlgItem(hCheat, IDC_BTN_CHEAT_ADDFROMFILE), FALSE); } else { - sprintf(temp, "%d Error: Too many cheats loaded!", FrozenAddressCount); + sprintf(temp, "%u Error: Too many cheats loaded!", FrozenAddressCount); EnableWindow(GetDlgItem(hCheat, IDC_BTN_CHEAT_ADD), FALSE); EnableWindow(GetDlgItem(hCheat, IDC_BTN_CHEAT_ADDFROMFILE), FALSE); } diff --git a/src/drivers/win/ramwatch.h b/src/drivers/win/ramwatch.h index fd625b9d..c1d765c6 100644 --- a/src/drivers/win/ramwatch.h +++ b/src/drivers/win/ramwatch.h @@ -52,11 +52,17 @@ struct AddressWatcher { unsigned int Address; // hardware address unsigned int CurValue; - char* comment = NULL; // NULL means no comment, non-NULL means allocated comment + char* comment; // NULL means no comment, non-NULL means allocated comment bool WrongEndian; 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, 'b' = binary, 'S' = separator short Cheats; // how many bytes are affected by cheat + + AddressWatcher(void) + { + Address = 0; CurValue = 0; comment = NULL; WrongEndian = false; + Size = 'b'; Type = 's'; Cheats = 0; + } }; // the struct for communicating with add watch window