CPPcheck audit, fixed some minor stuff

This commit is contained in:
d0k3 2018-02-06 00:29:21 +01:00
parent 7927c742c6
commit b204921554
6 changed files with 10 additions and 10 deletions

View File

@ -26,6 +26,7 @@ u64 IdentifyFileType(const char* path) {
// block crappy "._" files from getting recognized as filetype // block crappy "._" files from getting recognized as filetype
if (!fname) return 0;
if (strncmp(fname, "._", 2) == 0) return 0; if (strncmp(fname, "._", 2) == 0) return 0;
if (ext) ext++; if (ext) ext++;
@ -110,7 +111,7 @@ u64 IdentifyFileType(const char* path) {
return GAME_3DSX; // 3DSX (executable) file return GAME_3DSX; // 3DSX (executable) file
} else if ((fsize > sizeof(NcchInfoHeader)) && } else if ((fsize > sizeof(NcchInfoHeader)) &&
(GetNcchInfoVersion((NcchInfoHeader*) data)) && (GetNcchInfoVersion((NcchInfoHeader*) data)) &&
fname && (strncasecmp(fname, NCCHINFO_NAME, 32) == 0)) { (strncasecmp(fname, NCCHINFO_NAME, 32) == 0)) {
return BIN_NCCHNFO; // ncchinfo.bin file return BIN_NCCHNFO; // ncchinfo.bin file
} else if ((fsize > sizeof(pcx_magic)) && (memcmp(data, pcx_magic, sizeof(pcx_magic)) == 0) && } else if ((fsize > sizeof(pcx_magic)) && (memcmp(data, pcx_magic, sizeof(pcx_magic)) == 0) &&
(strncasecmp(ext, "pcx", 4) == 0)) { (strncasecmp(ext, "pcx", 4) == 0)) {

View File

@ -48,7 +48,6 @@ bool FormatSDCard(u64 hidden_mb, u32 cluster_size, const char* label) {
ShowPrompt(false, "Error: SD card is too small"); ShowPrompt(false, "Error: SD card is too small");
return false; return false;
} }
sd_size = fat_size;
// build the MBR // build the MBR
memcpy(mbrdata + 0x08, &fat_sector, 4); memcpy(mbrdata + 0x08, &fat_sector, 4);

View File

@ -98,7 +98,7 @@ u32 cardEepromGetSize() {
if(type == 2) { if(type == 2) {
u32 buf1,buf2,buf3; u32 buf1,buf2,buf3;
cardReadEeprom(0,(u8*)&buf1,4,type); cardReadEeprom(0,(u8*)&buf1,4,type);
if ( !(buf1 != 0 || buf1 != 0xffffffff) ) { if ( !(buf1 != 0 && buf1 != 0xffffffff) ) {
buf3 = ~buf1; buf3 = ~buf1;
cardWriteEeprom(0,(u8*)&buf3,4,type); cardWriteEeprom(0,(u8*)&buf3,4,type);
} else { } else {

View File

@ -778,7 +778,7 @@ u32 Sha256Calculator(const char* path) {
bool have_sha = (FileGetData(sha_path, sha256_file, 32, 0) == 32); bool have_sha = (FileGetData(sha_path, sha256_file, 32, 0) == 32);
bool match_sha = have_sha && (memcmp(sha256, sha256_file, 32) == 0); bool match_sha = have_sha && (memcmp(sha256, sha256_file, 32) == 0);
bool match_prev = (memcmp(sha256, sha256_prev, 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", 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), pathstr, getbe64(sha256 + 0), getbe64(sha256 + 8), getbe64(sha256 + 16), getbe64(sha256 + 24),
(have_sha) ? "\nSHA verification: " : "", (have_sha) ? "\nSHA verification: " : "",

View File

@ -122,8 +122,8 @@ u32 BuildKeyDb(const char* path, bool dump) {
memset(&key, 0, sizeof(AesKeyInfo)); memset(&key, 0, sizeof(AesKeyInfo));
key.type = 'N'; key.type = 'N';
if (!name_in || (strnlen(++name_in, 32) > 24)) return 1; // safety if (!name_in || (strnlen(++name_in, 32) > 24)) return 1; // safety
if ((sscanf(name_in, "slot0x%02XKey%s", &keyslot, typestr) != 2) && if ((sscanf(name_in, "slot0x%02XKey%31s", &keyslot, typestr) != 2) &&
(sscanf(name_in, "slot0x%02Xkey%s", &keyslot, typestr) != 2)) return 1; (sscanf(name_in, "slot0x%02Xkey%31s", &keyslot, typestr) != 2)) return 1;
char* ext = strchr(typestr, '.'); char* ext = strchr(typestr, '.');
if (!ext) return 1; if (!ext) return 1;

View File

@ -56,7 +56,7 @@
// some useful macros // some useful macros
#define IS_WHITESPACE(c) ((c == ' ') || (c == '\t') || (c == '\r') || (c == '\n')) #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 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) || \ #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) || \ (id == CMD_ID_GOTO) || (id == CMD_ID_LABELSEL) || \
@ -384,8 +384,8 @@ void upd_var(const char* name) {
get_dstime(&dstime); get_dstime(&dstime);
char env_date[16+1]; char env_date[16+1];
char env_time[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_date, 16, "%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_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, "DATESTAMP", _VAR_NAME_LEN) == 0)) set_var("DATESTAMP", env_date);
if (!name || (strncmp(name, "TIMESTAMP", _VAR_NAME_LEN) == 0)) set_var("TIMESTAMP", env_time); 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"); if (err_str) snprintf(err_str, _ERR_STR_LEN, "argv[2] must be 2 chars");
ret = false; ret = false;
} else { } 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]; if (str[i] == argv[2][0]) str[i] = argv[2][1];
} }
ret = set_var(argv[0], str); ret = set_var(argv[0], str);