From b2049215544cde58c61b06e41a5ae59b9ca74ac5 Mon Sep 17 00:00:00 2001 From: d0k3 Date: Tue, 6 Feb 2018 00:29:21 +0100 Subject: [PATCH] CPPcheck audit, fixed some minor stuff --- arm9/source/filesys/filetype.c | 3 ++- arm9/source/filesys/fsutil.c | 1 - arm9/source/gamecart/card_eeprom.c | 2 +- arm9/source/godmode.c | 2 +- arm9/source/utils/keydbutil.c | 4 ++-- arm9/source/utils/scripting.c | 8 ++++---- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/arm9/source/filesys/filetype.c b/arm9/source/filesys/filetype.c index 2100507..0174f2e 100644 --- a/arm9/source/filesys/filetype.c +++ b/arm9/source/filesys/filetype.c @@ -26,6 +26,7 @@ u64 IdentifyFileType(const char* path) { // block crappy "._" files from getting recognized as filetype + if (!fname) return 0; if (strncmp(fname, "._", 2) == 0) return 0; if (ext) ext++; @@ -110,7 +111,7 @@ u64 IdentifyFileType(const char* path) { return GAME_3DSX; // 3DSX (executable) file } else if ((fsize > sizeof(NcchInfoHeader)) && (GetNcchInfoVersion((NcchInfoHeader*) data)) && - fname && (strncasecmp(fname, NCCHINFO_NAME, 32) == 0)) { + (strncasecmp(fname, NCCHINFO_NAME, 32) == 0)) { return BIN_NCCHNFO; // ncchinfo.bin file } else if ((fsize > sizeof(pcx_magic)) && (memcmp(data, pcx_magic, sizeof(pcx_magic)) == 0) && (strncasecmp(ext, "pcx", 4) == 0)) { diff --git a/arm9/source/filesys/fsutil.c b/arm9/source/filesys/fsutil.c index 7ecb58c..a1a4ee3 100644 --- a/arm9/source/filesys/fsutil.c +++ b/arm9/source/filesys/fsutil.c @@ -48,7 +48,6 @@ bool FormatSDCard(u64 hidden_mb, u32 cluster_size, const char* label) { ShowPrompt(false, "Error: SD card is too small"); return false; } - sd_size = fat_size; // build the MBR memcpy(mbrdata + 0x08, &fat_sector, 4); diff --git a/arm9/source/gamecart/card_eeprom.c b/arm9/source/gamecart/card_eeprom.c index 88b04be..5124c99 100644 --- a/arm9/source/gamecart/card_eeprom.c +++ b/arm9/source/gamecart/card_eeprom.c @@ -98,7 +98,7 @@ u32 cardEepromGetSize() { if(type == 2) { u32 buf1,buf2,buf3; cardReadEeprom(0,(u8*)&buf1,4,type); - if ( !(buf1 != 0 || buf1 != 0xffffffff) ) { + if ( !(buf1 != 0 && buf1 != 0xffffffff) ) { buf3 = ~buf1; cardWriteEeprom(0,(u8*)&buf3,4,type); } else { diff --git a/arm9/source/godmode.c b/arm9/source/godmode.c index e1b31c2..4b7e30f 100644 --- a/arm9/source/godmode.c +++ b/arm9/source/godmode.c @@ -778,7 +778,7 @@ u32 Sha256Calculator(const char* path) { bool have_sha = (FileGetData(sha_path, sha256_file, 32, 0) == 32); bool match_sha = have_sha && (memcmp(sha256, sha256_file, 32) == 0); bool match_prev = (memcmp(sha256, sha256_prev, 32) == 0); - bool write_sha = (!have_sha || (have_sha && !match_sha)) && (drvtype & DRV_SDCARD); // writing only on SD + bool write_sha = (!have_sha || !match_sha) && (drvtype & DRV_SDCARD); // writing only on SD if (ShowPrompt(write_sha, "%s\n%016llX%016llX\n%016llX%016llX%s%s%s%s%s", pathstr, getbe64(sha256 + 0), getbe64(sha256 + 8), getbe64(sha256 + 16), getbe64(sha256 + 24), (have_sha) ? "\nSHA verification: " : "", diff --git a/arm9/source/utils/keydbutil.c b/arm9/source/utils/keydbutil.c index c1d80ff..1dc6ca0 100644 --- a/arm9/source/utils/keydbutil.c +++ b/arm9/source/utils/keydbutil.c @@ -122,8 +122,8 @@ u32 BuildKeyDb(const char* path, bool dump) { memset(&key, 0, sizeof(AesKeyInfo)); key.type = 'N'; if (!name_in || (strnlen(++name_in, 32) > 24)) return 1; // safety - if ((sscanf(name_in, "slot0x%02XKey%s", &keyslot, typestr) != 2) && - (sscanf(name_in, "slot0x%02Xkey%s", &keyslot, typestr) != 2)) return 1; + if ((sscanf(name_in, "slot0x%02XKey%31s", &keyslot, typestr) != 2) && + (sscanf(name_in, "slot0x%02Xkey%31s", &keyslot, typestr) != 2)) return 1; char* ext = strchr(typestr, '.'); if (!ext) return 1; diff --git a/arm9/source/utils/scripting.c b/arm9/source/utils/scripting.c index bdea3c1..2e81e38 100644 --- a/arm9/source/utils/scripting.c +++ b/arm9/source/utils/scripting.c @@ -56,7 +56,7 @@ // some useful macros #define IS_WHITESPACE(c) ((c == ' ') || (c == '\t') || (c == '\r') || (c == '\n')) #define MATCH_STR(s,l,c) ((l == strlen(c)) && (strncmp(s, c, l) == 0)) -#define _FLG(c) (1 << (c - 'a')) +#define _FLG(c) ((c >= 'a') ? (1 << (c - 'a')) : 0) #define IS_CTRLFLOW_CMD(id) ((id == CMD_ID_IF) || (id == CMD_ID_ELIF) || (id == CMD_ID_ELSE) || (id == CMD_ID_END) || \ (id == CMD_ID_GOTO) || (id == CMD_ID_LABELSEL) || \ @@ -384,8 +384,8 @@ void upd_var(const char* name) { get_dstime(&dstime); char env_date[16+1]; char env_time[16+1]; - snprintf(env_date, _VAR_CNT_LEN, "%02lX%02lX%02lX", (u32) dstime.bcd_Y, (u32) dstime.bcd_M, (u32) dstime.bcd_D); - snprintf(env_time, _VAR_CNT_LEN, "%02lX%02lX%02lX", (u32) dstime.bcd_h, (u32) dstime.bcd_m, (u32) dstime.bcd_s); + snprintf(env_date, 16, "%02lX%02lX%02lX", (u32) dstime.bcd_Y, (u32) dstime.bcd_M, (u32) dstime.bcd_D); + snprintf(env_time, 16, "%02lX%02lX%02lX", (u32) dstime.bcd_h, (u32) dstime.bcd_m, (u32) dstime.bcd_s); if (!name || (strncmp(name, "DATESTAMP", _VAR_NAME_LEN) == 0)) set_var("DATESTAMP", env_date); if (!name || (strncmp(name, "TIMESTAMP", _VAR_NAME_LEN) == 0)) set_var("TIMESTAMP", env_time); } @@ -1018,7 +1018,7 @@ bool run_cmd(cmd_id id, u32 flags, char** argv, char* err_str) { if (err_str) snprintf(err_str, _ERR_STR_LEN, "argv[2] must be 2 chars"); ret = false; } else { - for (u32 i = 0; str[i] && (i < _ARG_MAX_LEN); i++) { + for (u32 i = 0; (i < _ARG_MAX_LEN) && str[i]; i++) { if (str[i] == argv[2][0]) str[i] = argv[2][1]; } ret = set_var(argv[0], str);