diff --git a/arm9/source/common/screenshot.c b/arm9/source/common/screenshot.c index 285a633..2deb659 100644 --- a/arm9/source/common/screenshot.c +++ b/arm9/source/common/screenshot.c @@ -27,7 +27,7 @@ void CreateScreenshot(void) { fvx_rmkdir(OUTPUT_PATH); get_dstime(&dstime); - snprintf(filename, 64, OUTPUT_PATH "/snap_%02X%02X%02X%02X%02X%02X.png", + snprintf(filename, sizeof(filename), OUTPUT_PATH "/snap_%02X%02X%02X%02X%02X%02X.png", dstime.bcd_Y, dstime.bcd_M, dstime.bcd_D, dstime.bcd_h, dstime.bcd_m, dstime.bcd_s); filename[63] = '\0'; diff --git a/arm9/source/common/swkbd.c b/arm9/source/common/swkbd.c index 9f4db7d..f410812 100644 --- a/arm9/source/common/swkbd.c +++ b/arm9/source/common/swkbd.c @@ -81,7 +81,7 @@ static void DrawKey(const TouchBox* key, const bool pressed, const u32 uppercase if (key->id == KEY_TXTBOX) return; char keystr[16]; - if (key->id >= 0x80) snprintf(keystr, 16, "%s", keystrs[key->id - 0x80]); + if (key->id >= 0x80) snprintf(keystr, sizeof(keystr), "%s", keystrs[key->id - 0x80]); else { keystr[0] = (uppercase) ? to_uppercase(key->id) : key->id; keystr[1] = 0; @@ -269,7 +269,7 @@ bool ShowKeyboard(char* inputstr, const u32 max_size, const char *format, ...) { char str[512]; // arbitrary limit, should be more than enough va_list va; va_start(va, format); - vsnprintf(str, 512, format, va); + vsnprintf(str, sizeof(str), format, va); va_end(va); u32 str_width = GetDrawStringWidth(str); if (str_width < (24 * FONT_WIDTH_EXT)) str_width = 24 * FONT_WIDTH_EXT; diff --git a/arm9/source/common/ui.c b/arm9/source/common/ui.c index ee1a198..e2de1eb 100644 --- a/arm9/source/common/ui.c +++ b/arm9/source/common/ui.c @@ -882,8 +882,8 @@ u32 ShowSelectPrompt(int n, const char** options, const char *format, ...) { // show [n more] if (n - n_show - scroll > 0) { - char more_str[UTF_BUFFER_BYTESIZE(str_width / font_width)], temp_str[64]; - snprintf(temp_str, 64, " [%d more]", (n - (n_show-1) - scroll)); + char more_str[UTF_BUFFER_BYTESIZE(str_width / font_width)], temp_str[UTF_BUFFER_BYTESIZE(64)]; + snprintf(temp_str, sizeof(temp_str), STR_N_MORE, (n - (n_show-1) - scroll)); ResizeString(more_str, temp_str, str_width / font_width, 8, false); DrawString(MAIN_SCREEN, more_str, x, yopt + (line_height+2)*(n_show-1), COLOR_LIGHTGREY, COLOR_STD_BG); } @@ -977,8 +977,8 @@ u32 ShowFileScrollPrompt(int n, const DirEntry** options, bool hide_ext, const c } // show [n more] if (n - n_show - scroll > 0) { - char more_str[UTF_BUFFER_BYTESIZE(item_width / font_width)], temp_str[64]; - snprintf(temp_str, 64, STR_N_MORE, (n - (n_show-1) - scroll)); + char more_str[UTF_BUFFER_BYTESIZE(item_width / font_width)], temp_str[UTF_BUFFER_BYTESIZE(64)]; + snprintf(temp_str, sizeof(temp_str), STR_N_MORE, (n - (n_show-1) - scroll)); ResizeString(more_str, temp_str, item_width / font_width, 8, false); DrawString(MAIN_SCREEN, more_str, x, yopt + (line_height+2)*(n_show-1), COLOR_LIGHTGREY, COLOR_STD_BG); } @@ -1265,7 +1265,7 @@ u64 ShowHexPrompt(u64 start_val, u32 n_digits, const char *format, ...) { va_list va; if (n_digits > 16) n_digits = 16; - snprintf(inputstr, 16 + 1, "%0*llX", (int) n_digits, start_val); + snprintf(inputstr, sizeof(inputstr), "%0*llX", (int) n_digits, start_val); va_start(va, format); if (ShowInputPrompt(inputstr, n_digits + 1, 0, alphabet, format, va)) { @@ -1282,7 +1282,7 @@ u64 ShowNumberPrompt(u64 start_val, const char *format, ...) { u64 ret = 0; va_list va; - snprintf(inputstr, 20 + 1, "%llu", start_val); + snprintf(inputstr, sizeof(inputstr), "%llu", start_val); va_start(va, format); if (ShowInputPrompt(inputstr, 20 + 1, 1, alphabet, format, va)) { @@ -1402,7 +1402,7 @@ bool ShowProgress(u64 current, u64 total, const char* opstr) const u32 text_pos_y = bar_pos_y + bar_height + 2; u32 prog_width = ((total > 0) && (current <= total)) ? (current * (bar_width-4)) / total : 0; u32 prog_percent = ((total > 0) && (current <= total)) ? (current * 100) / total : 0; - char tempstr[64]; + char tempstr[UTF_BUFFER_BYTESIZE(64)]; char progstr[UTF_BUFFER_BYTESIZE(64)]; static u64 last_msec_elapsed = 0; @@ -1427,11 +1427,11 @@ bool ShowProgress(u64 current, u64 total, const char* opstr) DrawRectangle(MAIN_SCREEN, bar_pos_x + 2 + prog_width, bar_pos_y + 2, (bar_width-4) - prog_width, bar_height - 4, COLOR_STD_BG); TruncateString(progstr, opstr, min(63, (bar_width / FONT_WIDTH_EXT) - 7), 8); - snprintf(tempstr, 64, "%s (%lu%%)", progstr, prog_percent); + snprintf(tempstr, sizeof(tempstr), "%s (%lu%%)", progstr, prog_percent); ResizeString(progstr, tempstr, bar_width / FONT_WIDTH_EXT, 8, false); DrawString(MAIN_SCREEN, progstr, bar_pos_x, text_pos_y, COLOR_STD_FONT, COLOR_STD_BG); if (sec_elapsed >= 1) { - snprintf(tempstr, 16, STR_ETA_N_MIN_N_SEC, sec_remain / 60, sec_remain % 60); + snprintf(tempstr, sizeof(tempstr), STR_ETA_N_MIN_N_SEC, sec_remain / 60, sec_remain % 60); ResizeString(progstr, tempstr, 16, 8, true); DrawString(MAIN_SCREEN, progstr, bar_pos_x + bar_width - 1 - (FONT_WIDTH_EXT * 16), bar_pos_y - line_height - 1, COLOR_STD_FONT, COLOR_STD_BG); diff --git a/arm9/source/crypto/keydb.c b/arm9/source/crypto/keydb.c index 3b41d68..6e72945 100644 --- a/arm9/source/crypto/keydb.c +++ b/arm9/source/crypto/keydb.c @@ -152,7 +152,7 @@ u32 LoadKeyFromFile(void* key, u32 keyslot, char type, char* id) // load legacy slot0x??Key?.bin file instead if (!found && (type != 'I')) { char fname[64]; - snprintf(fname, 64, "slot0x%02lXKey%s%s.bin", keyslot, + snprintf(fname, sizeof(fname), "slot0x%02lXKey%s%s.bin", keyslot, (type == 'X') ? "X" : (type == 'Y') ? "Y" : (type == 'I') ? "IV" : "", (id) ? id : ""); found = (LoadSupportFile(fname, key, 16) == 16); } diff --git a/arm9/source/filesys/fsdrive.c b/arm9/source/filesys/fsdrive.c index de23d89..ce3e21b 100644 --- a/arm9/source/filesys/fsdrive.c +++ b/arm9/source/filesys/fsdrive.c @@ -232,7 +232,7 @@ uint64_t GetFreeSpace(const char* path) FATFS* fsobj = GetMountedFSObject(path); if ((pdrv < 0) || !fsobj) return 0; - snprintf(fsname, 3, "%i:", pdrv); + snprintf(fsname, sizeof(fsname), "%i:", pdrv); if (f_getfree(fsname, &free_clusters, &fsptr) != FR_OK) return 0; diff --git a/arm9/source/filesys/fsinit.c b/arm9/source/filesys/fsinit.c index c80d34e..f0183dc 100644 --- a/arm9/source/filesys/fsinit.c +++ b/arm9/source/filesys/fsinit.c @@ -21,7 +21,7 @@ bool InitExtFS() { for (u32 i = 1; i < NORM_FS; i++) { char fsname[8]; - snprintf(fsname, 7, "%lu:", i); + snprintf(fsname, sizeof(fsname), "%lu:", i); if (fs_mounted[i]) continue; fs_mounted[i] = (f_mount(fs + i, fsname, 1) == FR_OK); if ((!fs_mounted[i] || !ramdrv_ready) && (i == NORM_FS - 1) && !(GetMountState() & IMG_NAND)) { @@ -44,7 +44,7 @@ bool InitImgFS(const char* path) { u32 drv_i = NORM_FS - IMGN_FS; char fsname[8]; for (; drv_i < NORM_FS; drv_i++) { - snprintf(fsname, 7, "%lu:", drv_i); + snprintf(fsname, sizeof(fsname), "%lu:", drv_i); if (!(DriveType(fsname)&DRV_IMAGE)) break; } // deinit virtual filesystem @@ -58,7 +58,7 @@ bool InitImgFS(const char* path) { else if ((type&IMG_FAT) && (drv_i < NORM_FS - IMGN_FS + 1)) drv_i = NORM_FS - IMGN_FS + 1; // reinit image filesystem for (u32 i = NORM_FS - IMGN_FS; i < drv_i; i++) { - snprintf(fsname, 7, "%lu:", i); + snprintf(fsname, sizeof(fsname), "%lu:", i); fs_mounted[i] = (f_mount(fs + i, fsname, 1) == FR_OK); } return GetMountState(); @@ -71,7 +71,7 @@ void DeinitExtFS() { for (u32 i = NORM_FS - 1; i > 0; i--) { if (fs_mounted[i]) { char fsname[8]; - snprintf(fsname, 7, "%lu:", i); + snprintf(fsname, sizeof(fsname), "%lu:", i); f_mount(NULL, fsname, 1); fs_mounted[i] = false; } @@ -91,7 +91,7 @@ void DismountDriveType(u32 type) { // careful with this - no safety checks } for (u32 i = 0; i < NORM_FS; i++) { char fsname[8]; - snprintf(fsname, 7, "%lu:", i); + snprintf(fsname, sizeof(fsname), "%lu:", i); if (!fs_mounted[i] || !(type & DriveType(fsname))) continue; f_mount(NULL, fsname, 1); diff --git a/arm9/source/filesys/fsperm.c b/arm9/source/filesys/fsperm.c index 35b6537..ae4eb60 100644 --- a/arm9/source/filesys/fsperm.c +++ b/arm9/source/filesys/fsperm.c @@ -21,7 +21,7 @@ static u32 write_permissions = PERM_BASE; bool CheckWritePermissions(const char* path) { - char area_name[16]; + char area_name[UTF_BUFFER_BYTESIZE(16)]; int drvtype = DriveType(path); u32 perm; @@ -64,7 +64,7 @@ bool CheckWritePermissions(const char* path) { if ((drvtype & DRV_CTRNAND) || (lvl == 2)) lvl = 3; } perm = perms[lvl]; - snprintf(area_name, 16, STR_SYSNAND_LVL_N, lvl); + snprintf(area_name, sizeof(area_name), STR_SYSNAND_LVL_N, lvl); } else if (drvtype & DRV_EMUNAND) { static const u32 perms[] = { PERM_EMU_LVL0, PERM_EMU_LVL1 }; u32 lvl = (drvtype & (DRV_ALIAS|DRV_CTRNAND)) ? 1 : 0; @@ -74,34 +74,34 @@ bool CheckWritePermissions(const char* path) { if (strncasecmp(path_f, path_lvl1[i], 256) == 0) lvl = 1; } perm = perms[lvl]; - snprintf(area_name, 16, STR_EMUNAND_LVL_N, lvl); + snprintf(area_name, sizeof(area_name), STR_EMUNAND_LVL_N, lvl); } else if (drvtype & DRV_GAME) { perm = PERM_GAME; - snprintf(area_name, 16, "%s", STR_GAME_IMAGES); + snprintf(area_name, sizeof(area_name), "%s", STR_GAME_IMAGES); } else if (drvtype & DRV_CART) { perm = PERM_CART; - snprintf(area_name, 16, "%s", STR_GAMECART_SAVES); + snprintf(area_name, sizeof(area_name), "%s", STR_GAMECART_SAVES); } else if (drvtype & DRV_VRAM) { perm = PERM_VRAM; - snprintf(area_name, 16, "vram0"); + snprintf(area_name, sizeof(area_name), "vram0"); } else if (drvtype & DRV_XORPAD) { perm = PERM_XORPAD; - snprintf(area_name, 16, "XORpads"); + snprintf(area_name, sizeof(area_name), "XORpads"); } else if (drvtype & DRV_IMAGE) { perm = PERM_IMAGE; - snprintf(area_name, 16, "%s", STR_IMAGES); + snprintf(area_name, sizeof(area_name), "%s", STR_IMAGES); } else if (drvtype & DRV_MEMORY) { perm = PERM_MEMORY; - snprintf(area_name, 16, "%s", STR_MEMORY_AREAS); + snprintf(area_name, sizeof(area_name), "%s", STR_MEMORY_AREAS); } else if (strncasecmp(path_f, "0:/Nintendo 3DS", 15) == 0) { // this check could be better perm = PERM_SDDATA; - snprintf(area_name, 16, "%s", STR_SD_SYSTEM_DATA); + snprintf(area_name, sizeof(area_name), "%s", STR_SD_SYSTEM_DATA); } else if (drvtype & DRV_SDCARD) { perm = PERM_SDCARD; - snprintf(area_name, 16, "%s", STR_SD_CARD); + snprintf(area_name, sizeof(area_name), "%s", STR_SD_CARD); } else if (drvtype & DRV_RAMDRIVE) { perm = PERM_RAMDRIVE; - snprintf(area_name, 16, "%s", STR_RAM_DRIVE); + snprintf(area_name, sizeof(area_name), "%s", STR_RAM_DRIVE); } else { return false; } diff --git a/arm9/source/filesys/fsutil.c b/arm9/source/filesys/fsutil.c index ad3d590..6b9cfd0 100644 --- a/arm9/source/filesys/fsutil.c +++ b/arm9/source/filesys/fsutil.c @@ -363,8 +363,8 @@ bool FileSetByte(const char* dest, u64 offset, u64 size, u8 fillbyte, u32* flags bool FileCreateDummy(const char* cpath, const char* filename, u64 size) { char npath[256]; // 256 is the maximum length of a full path if (!CheckWritePermissions(cpath)) return false; - if (filename) snprintf(npath, 255, "%s/%s", cpath, filename); - else snprintf(npath, 255, "%s", cpath); + if (filename) snprintf(npath, sizeof(npath), "%s/%s", cpath, filename); + else snprintf(npath, sizeof(npath), "%s", cpath); // create dummy file (fail if already existing) // then, expand the file size via cluster preallocation @@ -381,7 +381,7 @@ bool FileCreateDummy(const char* cpath, const char* filename, u64 size) { bool DirCreate(const char* cpath, const char* dirname) { char npath[256]; // 256 is the maximum length of a full path if (!CheckWritePermissions(cpath)) return false; - snprintf(npath, 255, "%s/%s", cpath, dirname); + snprintf(npath, sizeof(npath), "%s/%s", cpath, dirname); if (fa_mkdir(npath) != FR_OK) return false; return (fa_stat(npath, NULL) == FR_OK); } @@ -731,7 +731,7 @@ bool PathCopy(const char* destdir, const char* orig, u32* flags) { char dest[256]; // maximum path name length in FAT char* oname = strrchr(orig, '/'); if (oname == NULL) return false; // not a proper origin path - snprintf(dest, 255, "%s/%s", destdir, (++oname)); + snprintf(dest, sizeof(dest), "%s/%s", destdir, (++oname)); // virtual destination special handling if (GetVirtualSource(destdir) & ~VRT_BDRI) { @@ -747,7 +747,7 @@ bool PathCopy(const char* destdir, const char* orig, u32* flags) { } if (!ShowPrompt(true, STR_ENTRY_NOT_FOUND_PATH_INJECT_INTO_PATH_INSTEAD, dest, dvfile.name)) return false; - snprintf(dest, 255, "%s/%s", destdir, dvfile.name); + snprintf(dest, sizeof(dest), "%s/%s", destdir, dvfile.name); } else if (osize < dvfile.size) { // if origin is smaller than destination... char deststr[UTF_BUFFER_BYTESIZE(36)]; char origstr[UTF_BUFFER_BYTESIZE(36)]; @@ -772,7 +772,7 @@ bool PathMove(const char* destdir, const char* orig, u32* flags) { char dest[256]; // maximum path name length in FAT char* oname = strrchr(orig, '/'); if (oname == NULL) return false; // not a proper origin path - snprintf(dest, 255, "%s/%s", destdir, (++oname)); + snprintf(dest, sizeof(dest), "%s/%s", destdir, (++oname)); return PathMoveCopy(dest, orig, flags, true); } @@ -838,7 +838,7 @@ bool FileSelectorWorker(char* result, const char* text, const char* path, const if (!new_style) { char temp_str[256]; - snprintf(temp_str, 256, "%s", entry->name); + snprintf(temp_str, sizeof(temp_str), "%s", entry->name); if (hide_ext && (entry->type == T_FILE)) { char* dot = strrchr(temp_str, '.'); if (dot) *dot = '\0'; diff --git a/arm9/source/filesys/sddata.c b/arm9/source/filesys/sddata.c index 1148cf2..cec19cf 100644 --- a/arm9/source/filesys/sddata.c +++ b/arm9/source/filesys/sddata.c @@ -276,7 +276,7 @@ bool SetupNandSdDrive(const char* path, const char* sd_path, const char* movable // build the alias path (id0) u32 sha256sum[8]; sha_quick(sha256sum, sd_keyy[num], 0x10, SHA256_MODE); - snprintf(alias, 127, "%s/Nintendo 3DS/%08lX%08lX%08lX%08lX", + snprintf(alias, sizeof(alias), "%s/Nintendo 3DS/%08lX%08lX%08lX%08lX", sd_path, sha256sum[0], sha256sum[1], sha256sum[2], sha256sum[3]); // find the alias path (id1) diff --git a/arm9/source/filesys/support.c b/arm9/source/filesys/support.c index 0f261d4..474237b 100644 --- a/arm9/source/filesys/support.c +++ b/arm9/source/filesys/support.c @@ -17,7 +17,7 @@ bool CheckSupportFile(const char* fname) const char* base_paths[] = { SUPPORT_FILE_PATHS }; for (u32 i = 0; i < countof(base_paths); i++) { char path[256]; - snprintf(path, 256, "%s/%s", base_paths[i], fname); + snprintf(path, sizeof(path), "%s/%s", base_paths[i], fname); if (fvx_stat(path, NULL) == FR_OK) return true; } @@ -40,7 +40,7 @@ size_t LoadSupportFile(const char* fname, void* buffer, size_t max_len) for (u32 i = 0; i < countof(base_paths); i++) { UINT len32; char path[256]; - snprintf(path, 256, "%s/%s", base_paths[i], fname); + snprintf(path, sizeof(path), "%s/%s", base_paths[i], fname); if (fvx_qread(path, buffer, 0, max_len, &len32) == FR_OK) return len32; } @@ -68,7 +68,7 @@ bool SaveSupportFile(const char* fname, void* buffer, size_t len) // write support file if (idx >= 0) { char path[256]; - snprintf(path, 256, "%s/%s", base_paths[idx], fname); + snprintf(path, sizeof(path), "%s/%s", base_paths[idx], fname); fvx_unlink(path); if (fvx_qwrite(path, buffer, 0, len, NULL) == FR_OK) return true; diff --git a/arm9/source/game/ips.c b/arm9/source/game/ips.c index db28221..a8f66f6 100644 --- a/arm9/source/game/ips.c +++ b/arm9/source/game/ips.c @@ -113,7 +113,7 @@ UINT read24() { int ApplyIPSPatch(const char* patchName, const char* inName, const char* outName) { int error = IPS_INVALID; UINT outlen_min, outlen_max, outlen_min_mem; - snprintf(errName, 256, "%s", patchName); + snprintf(errName, sizeof(errName), "%s", patchName); if (fvx_open(&patchFile, patchName, FA_READ) != FR_OK) return displayError(IPS_INVALID_FILE_PATH); patchSize = fvx_size(&patchFile); diff --git a/arm9/source/godmode.c b/arm9/source/godmode.c index 9c338d9..6776bf3 100644 --- a/arm9/source/godmode.c +++ b/arm9/source/godmode.c @@ -90,8 +90,8 @@ u32 BootFirmHandler(const char* bootpath, bool verbose, bool delete) { // unsupported location handling char fixpath[256] = { 0 }; if (verbose && (*bootpath != '0') && (*bootpath != '1')) { - char str[256]; - snprintf(str, 256, STR_MAKE_COPY_AT_OUT_TEMP_FIRM, OUTPUT_PATH); + char str[UTF_BUFFER_BYTESIZE(256)]; + snprintf(str, sizeof(str), STR_MAKE_COPY_AT_OUT_TEMP_FIRM, OUTPUT_PATH); const char* optionstr[2] = { str, STR_TRY_BOOT_ANYWAYS }; u32 user_select = ShowSelectPrompt(2, optionstr, "%s\n%s", pathstr, STR_WARNING_BOOT_UNSUPPORTED_LOCATION); if (user_select == 1) { @@ -102,7 +102,7 @@ u32 BootFirmHandler(const char* bootpath, bool verbose, bool delete) { // fix the boot path ("sdmc"/"nand" for Luma et al, hacky af) if ((*bootpath == '0') || (*bootpath == '1')) - snprintf(fixpath, 256, "%s%s", (*bootpath == '0') ? "sdmc" : "nand", bootpath + 1); + snprintf(fixpath, sizeof(fixpath), "%s%s", (*bootpath == '0') ? "sdmc" : "nand", bootpath + 1); else strncpy(fixpath, bootpath, 256); fixpath[255] = '\0'; @@ -164,7 +164,7 @@ static DirStruct* current_dir = NULL; static DirStruct* clipboard = NULL; static PaneData* panedata = NULL; -void GetTimeString(char* timestr, bool forced_update, bool full_year) { +void GetTimeString(char* timestr, bool forced_update, bool full_year) { // timestr should be 32 bytes static DsTime dstime; static u64 timer = (u64) -1; // this ensures we don't check the time too often if (forced_update || (timer == (u64) -1) || (timer_sec(timer) > 30)) { @@ -239,7 +239,7 @@ void DrawTopBar(const char* curr_path) { // top bar - current path DrawRectangle(TOP_SCREEN, 0, 0, SCREEN_WIDTH_TOP, 12, COLOR_TOP_BAR); if (*curr_path) TruncateString(tempstr, curr_path, min(63, len_path / FONT_WIDTH_EXT), 8); - else snprintf(tempstr, 16, "%s", STR_ROOT); + else snprintf(tempstr, sizeof(tempstr), "%s", STR_ROOT); DrawStringF(TOP_SCREEN, bartxt_x, bartxt_start, COLOR_STD_BG, COLOR_TOP_BAR, "%s", tempstr); bool show_time = true; @@ -253,7 +253,7 @@ void DrawTopBar(const char* curr_path) { DrawString(TOP_SCREEN, tempstr, bartxt_rx, bartxt_start, COLOR_STD_BG, COLOR_TOP_BAR); FormatBytes(bytestr0, GetFreeSpace(curr_path)); FormatBytes(bytestr1, GetTotalSpace(curr_path)); - snprintf(tempstr, 64, "%s/%s", bytestr0, bytestr1); + snprintf(tempstr, sizeof(tempstr), "%s/%s", bytestr0, bytestr1); DrawStringF(TOP_SCREEN, bartxt_rx, bartxt_start, COLOR_STD_BG, COLOR_TOP_BAR, "%19.19s", tempstr); show_time = false; } @@ -305,8 +305,8 @@ void DrawUserInterface(const char* curr_path, DirEntry* curr_entry, u32 curr_pan } // left top - current file info - if (curr_pane) snprintf(tempstr, 63, STR_PANE_N, curr_pane); - else snprintf(tempstr, 63, "%s", STR_CURRENT); + if (curr_pane) snprintf(tempstr, sizeof(tempstr), STR_PANE_N, curr_pane); + else snprintf(tempstr, sizeof(tempstr), "%s", STR_CURRENT); DrawStringF(MAIN_SCREEN, 2, info_start, COLOR_STD_FONT, COLOR_STD_BG, "[%s]", tempstr); // file / entry name ResizeString(tempstr, curr_entry->name, str_len_info, 8, false); @@ -316,7 +316,7 @@ void DrawUserInterface(const char* curr_path, DirEntry* curr_entry, u32 curr_pan if (curr_entry->type == T_DIR) { ResizeString(tempstr, STR_DIR, str_len_info, 8, false); } else if (curr_entry->type == T_DOTDOT) { - snprintf(tempstr, 21, "%20s", ""); + snprintf(tempstr, sizeof(tempstr), "%20s", ""); } else if (curr_entry->type == T_ROOT) { int drvtype = DriveType(curr_entry->path); const char* drvstr = @@ -331,7 +331,7 @@ void DrawUserInterface(const char* curr_path, DirEntry* curr_entry, u32 curr_pan char numstr[UTF_BUFFER_BYTESIZE(32)]; char bytestr[UTF_BUFFER_BYTESIZE(32)]; FormatNumber(numstr, curr_entry->size); - snprintf(bytestr, 31, STR_N_BYTE, numstr); + snprintf(bytestr, sizeof(bytestr), STR_N_BYTE, numstr); ResizeString(tempstr, bytestr, str_len_info, 8, false); } DrawStringF(MAIN_SCREEN, 4, info_start + 12 + 10, color_current, COLOR_STD_BG, "%s", tempstr); @@ -356,13 +356,13 @@ void DrawUserInterface(const char* curr_path, DirEntry* curr_entry, u32 curr_pan DrawStringF(MAIN_SCREEN, SCREEN_WIDTH_MAIN - len_info - 4, info_start + 12 + (c*10), color_cb, COLOR_STD_BG, "%s", tempstr); } *tempstr = '\0'; - if (clipboard->n_entries > n_cb_show) snprintf(tempstr, 60, STR_PLUS_N_MORE, clipboard->n_entries - n_cb_show); + if (clipboard->n_entries > n_cb_show) snprintf(tempstr, sizeof(tempstr), STR_PLUS_N_MORE, clipboard->n_entries - n_cb_show); DrawStringF(MAIN_SCREEN, SCREEN_WIDTH_MAIN - len_info - 4, info_start + 12 + (n_cb_show*10), COLOR_DARKGREY, COLOR_STD_BG, "%*s", (int) (len_info / FONT_WIDTH_EXT), tempstr); // bottom: instruction block - char instr[512]; - snprintf(instr, 512, "%s\n%s%s%s%s%s%s%s%s", + char instr[UTF_BUFFER_BYTESIZE(512)]; + snprintf(instr, sizeof(instr), "%s\n%s%s%s%s%s%s%s%s", FLAVOR " " VERSION, // generic start part (*curr_path) ? ((clipboard->n_entries == 0) ? STR_MARK_DELETE_COPY : STR_MARK_DELETE_PASTE) : ((GetWritePermissions() > PERM_BASE) ? STR_RELOCK_WRITE_PERMISSION : ""), @@ -401,8 +401,8 @@ void DrawDirContents(DirStruct* contents, u32 cursor, u32* scroll) { FormatBytes(rawbytestr, curr_entry->size); ResizeString(bytestr, (curr_entry->type == T_DIR) ? STR_DIR : (curr_entry->type == T_DOTDOT) ? "(..)" : rawbytestr, 10, 10, true); ResizeString(namestr, curr_entry->name, str_width - 10, str_width - 20, false); - snprintf(tempstr, UTF_BUFFER_BYTESIZE(str_width), "%s%s", namestr, bytestr); - } else snprintf(tempstr, str_width + 1, "%-*.*s", str_width, str_width, ""); + snprintf(tempstr, sizeof(tempstr), "%s%s", namestr, bytestr); + } else snprintf(tempstr, sizeof(tempstr), "%-*.*s", str_width, str_width, ""); DrawString(ALT_SCREEN, tempstr, pos_x, pos_y, color_font, COLOR_STD_BG); pos_y += stp_y; } @@ -459,7 +459,7 @@ u32 SdFormatMenu(const char* slabel) { if (!user_select) return 1; else cluster_size = cluster_size_table[user_select]; - snprintf(label, DRV_LABEL_LEN + 4, "0:%s", (slabel && *slabel) ? slabel : "GM9SD"); + snprintf(label, sizeof(label), "0:%s", (slabel && *slabel) ? slabel : "GM9SD"); if (!ShowKeyboardOrPrompt(label + 2, 11 + 1, STR_FORMAT_SD_ENTER_LABEL, sdcard_size_mb)) return 1; @@ -860,17 +860,17 @@ u32 ShaCalculator(const char* path, bool sha1) { char sha_path[256]; u8 sha_file[32]; - snprintf(sha_path, 256, "%s.sha%c", path, sha1 ? '1' : '\0'); + snprintf(sha_path, sizeof(sha_path), "%s.sha%c", path, sha1 ? '1' : '\0'); bool have_sha = (FileGetData(sha_path, sha_file, hashlen, 0) == hashlen); bool match_sha = have_sha && (memcmp(hash, sha_file, hashlen) == 0); bool match_prev = (memcmp(hash, hash_prev, hashlen) == 0); bool write_sha = (!have_sha || !match_sha) && (drvtype & DRV_SDCARD); // writing only on SD char hash_str[32+1+32+1]; if (sha1) - snprintf(hash_str, 20+1+20+1, "%016llX%04X\n%016llX%04X", getbe64(hash + 0), getbe16(hash + 8), + snprintf(hash_str, sizeof(hash_str), "%016llX%04X\n%016llX%04X", getbe64(hash + 0), getbe16(hash + 8), getbe64(hash + 10), getbe16(hash + 18)); else - snprintf(hash_str, 32+1+32+1, "%016llX%016llX\n%016llX%016llX", getbe64(hash + 0), getbe64(hash + 8), + snprintf(hash_str, sizeof(hash_str), "%016llX%016llX\n%016llX%016llX", getbe64(hash + 0), getbe64(hash + 8), getbe64(hash + 16), getbe64(hash + 24)); if (ShowPrompt(write_sha, "%s\n%s%s%s%s%s", pathstr, hash_str, @@ -987,7 +987,7 @@ u32 CartRawDump(void) { !ShowPrompt(true, STR_NDS_CART_DECRYPT_SECURE_AREA, cname)); // destination path - snprintf(dest, 256, "%s/%s_%08llX.%s", + snprintf(dest, sizeof(dest), "%s/%s_%08llX.%s", OUTPUT_PATH, cname, dsize, (cdata->cart_type & CART_CTR) ? "3ds" : "nds"); // buffer allocation @@ -1023,7 +1023,7 @@ u32 CartRawDump(void) { u32 DirFileAttrMenu(const char* path, const char *name) { bool drv = (path[2] == '\0'); bool vrt = (!drv); // will be checked below - char namestr[128], datestr[32], attrstr[128], sizestr[192]; + char namestr[UTF_BUFFER_BYTESIZE(128)], datestr[UTF_BUFFER_BYTESIZE(32)], attrstr[UTF_BUFFER_BYTESIZE(128)], sizestr[UTF_BUFFER_BYTESIZE(192)]; FILINFO fno; u8 new_attrib; @@ -1035,7 +1035,7 @@ u32 DirFileAttrMenu(const char* path, const char *name) { if (fvx_stat(path, &fno) != FR_OK) return 1; vrt = (fno.fattrib & AM_VRT); new_attrib = fno.fattrib; - snprintf(datestr, 32, "%s: %04d-%02d-%02d %02d:%02d:%02d\n", + snprintf(datestr, sizeof(datestr), "%s: %04d-%02d-%02d %02d:%02d:%02d\n", (fno.fattrib & AM_DIR) ? STR_CREATED : STR_MODIFIED, 1980 + ((fno.fdate >> 9) & 0x7F), (fno.fdate >> 5) & 0xF, fno.fdate & 0x1F, (fno.ftime >> 11) & 0x1F, (fno.ftime >> 5) & 0x3F, (fno.ftime & 0x1F) << 1); @@ -1063,20 +1063,20 @@ u32 DirFileAttrMenu(const char* path, const char *name) { FormatBytes(freestr, GetFreeSpace(path)); FormatBytes(drvsstr, GetTotalSpace(path)); FormatBytes(usedstr, GetTotalSpace(path) - GetFreeSpace(path)); - snprintf(sizestr, 192, STR_N_FILES_N_SUBDIRS_TOTAL_SIZE_FREE_USED_TOTAL, + snprintf(sizestr, sizeof(sizestr), STR_N_FILES_N_SUBDIRS_TOTAL_SIZE_FREE_USED_TOTAL, tfiles, tdirs, bytestr, freestr, usedstr, drvsstr); } else { // dir specific - snprintf(sizestr, 192, STR_N_FILES_N_SUBDIRS_TOTAL_SIZE, tfiles, tdirs, bytestr); + snprintf(sizestr, sizeof(sizestr), STR_N_FILES_N_SUBDIRS_TOTAL_SIZE, tfiles, tdirs, bytestr); } } else { // for files char bytestr[32]; FormatBytes(bytestr, fno.fsize); - snprintf(sizestr, 64, STR_FILESIZE_X, bytestr); + snprintf(sizestr, sizeof(sizestr), STR_FILESIZE_X, bytestr); } while(true) { if (!drv) { - snprintf(attrstr, 128, + snprintf(attrstr, sizeof(attrstr), STR_READONLY_HIDDEN_SYSTEM_ARCHIVE_VIRTUAL, (new_attrib & AM_RDO) ? 'X' : ' ', vrt ? "" : "↑", (new_attrib & AM_HID) ? 'X' : ' ', vrt ? "" : "↓", @@ -1213,7 +1213,7 @@ u32 FileHandlerMenu(char* current_path, u32* cursor, u32* scroll, PaneData** pan TruncateString(pathstr, file_path, 32, 8); char tidstr[32] = { 0 }; - if (tid) snprintf(tidstr, 32, "\ntid: <%016llX>", tid); + if (tid) snprintf(tidstr, sizeof(tidstr), "\ntid: <%016llX>", tid); u32 n_marked = 0; if ((&(current_dir->entry[*cursor]))->marked) { @@ -1536,8 +1536,8 @@ u32 FileHandlerMenu(char* current_path, u32* cursor, u32* scroll, PaneData** pan } else if (user_select == decrypt) { // -> decrypt game file if (cryptable_inplace) { - char decryptToOut[64]; - snprintf(decryptToOut, 64, STR_DECRYPT_TO_OUT, OUTPUT_PATH); + char decryptToOut[UTF_BUFFER_BYTESIZE(64)]; + snprintf(decryptToOut, sizeof(decryptToOut), STR_DECRYPT_TO_OUT, OUTPUT_PATH); optionstr[0] = decryptToOut; optionstr[1] = STR_DECRYPT_INPLACE; user_select = (int) ((n_marked > 1) ? @@ -1593,14 +1593,13 @@ u32 FileHandlerMenu(char* current_path, u32* cursor, u32* scroll, PaneData** pan } else if (user_select == encrypt) { // -> encrypt game file if (cryptable_inplace) { - char* encryptToOut = (char*)malloc(64); - snprintf(encryptToOut, 64, STR_ENCRYPT_TO_OUT, OUTPUT_PATH); + char encryptToOut[UTF_BUFFER_BYTESIZE(64)]; + snprintf(encryptToOut, sizeof(encryptToOut), STR_ENCRYPT_TO_OUT, OUTPUT_PATH); optionstr[0] = encryptToOut; optionstr[1] = STR_ENCRYPT_INPLACE; user_select = (int) ((n_marked > 1) ? ShowSelectPrompt(2, optionstr, STR_PATH_N_FILES_SELECTED, pathstr, n_marked) : ShowSelectPrompt(2, optionstr, "%s%s", pathstr, tidstr)); - free(encryptToOut); } else user_select = 1; bool inplace = (user_select == 2); if (!user_select) { // do nothing when no choice is made @@ -2609,10 +2608,10 @@ u32 GodMode(int entrypoint) { if ((pad_state & BUTTON_A) && (curr_entry->type != T_FILE) && (curr_entry->type != T_DOTDOT)) { // for dirs if (switched && !(DriveType(curr_entry->path) & (DRV_SEARCH|DRV_TITLEMAN))) { // exclude Y/Z const char* optionstr[8] = { NULL }; - char tpath[16] = { 0 }, copyToOut[64] = { 0 }, dumpToOut[64] = { 0 }; - snprintf(tpath, 16, "%2.2s/dbs/title.db", curr_entry->path); - snprintf(copyToOut, 64, STR_COPY_TO_OUT, OUTPUT_PATH); - snprintf(dumpToOut, 64, STR_DUMP_TO_OUT, OUTPUT_PATH); + char tpath[16], copyToOut[UTF_BUFFER_BYTESIZE(64)], dumpToOut[UTF_BUFFER_BYTESIZE(64)]; + snprintf(tpath, sizeof(tpath), "%2.2s/dbs/title.db", curr_entry->path); + snprintf(copyToOut, sizeof(copyToOut), STR_COPY_TO_OUT, OUTPUT_PATH); + snprintf(dumpToOut, sizeof(dumpToOut), STR_DUMP_TO_OUT, OUTPUT_PATH); int n_opt = 0; int tman = (!(DriveType(curr_entry->path) & DRV_IMAGE) && ((strncmp(curr_entry->path, tpath, 16) == 0) || @@ -2635,18 +2634,18 @@ u32 GodMode(int entrypoint) { if (user_select == tman) { if (InitImgFS(tpath)) { SetTitleManagerMode(true); - snprintf(current_path, 256, "Y:"); + snprintf(current_path, sizeof(current_path), "Y:"); GetDirContents(current_dir, current_path); cursor = 1; scroll = 0; } else ShowPrompt(false, "%s", STR_FAILED_SETTING_UP_TITLE_MANAGER); } else if (user_select == srch_f) { char searchstr[256]; - snprintf(searchstr, 256, "*"); + snprintf(searchstr, sizeof(searchstr), "*"); TruncateString(namestr, curr_entry->name, 20, 8); if (ShowKeyboardOrPrompt(searchstr, 256, STR_SEARCH_FILE_ENTER_SEARCH_BELOW, namestr)) { SetFSSearch(searchstr, curr_entry->path); - snprintf(current_path, 256, "Z:"); + snprintf(current_path, sizeof(current_path), "Z:"); GetDirContents(current_dir, current_path); if (current_dir->n_entries) ShowPrompt(false, STR_FOUND_N_RESULTS, current_dir->n_entries - 1); cursor = 1; @@ -2833,14 +2832,14 @@ u32 GodMode(int entrypoint) { ShowPrompt(false, "%s", STR_NOT_ALLOWED_IN_GAMECART_DRIVE); } else if (pad_state & BUTTON_Y) { // paste files const char* optionstr[2] = { STR_COPY_PATHS, STR_MOVE_PATHS }; - char promptstr[64]; + char promptstr[UTF_BUFFER_BYTESIZE(64)]; u32 flags = 0; u32 user_select; if (clipboard->n_entries == 1) { char namestr[UTF_BUFFER_BYTESIZE(20)]; TruncateString(namestr, clipboard->entry[0].name, 20, 12); - snprintf(promptstr, 64, STR_PASTE_FILE_HERE, namestr); - } else snprintf(promptstr, 64, STR_PASTE_N_PATHS_HERE, clipboard->n_entries); + snprintf(promptstr, sizeof(promptstr), STR_PASTE_FILE_HERE, namestr); + } else snprintf(promptstr, sizeof(promptstr), STR_PASTE_N_PATHS_HERE, clipboard->n_entries); user_select = ((DriveType(clipboard->entry[0].path) & curr_drvtype & DRV_STDFAT)) ? ShowSelectPrompt(2, optionstr, "%s", promptstr) : (ShowPrompt(true, "%s", promptstr) ? 1 : 0); if (user_select) { @@ -2873,7 +2872,7 @@ u32 GodMode(int entrypoint) { char newname[256]; char namestr[UTF_BUFFER_BYTESIZE(20)]; TruncateString(namestr, curr_entry->name, 20, 12); - snprintf(newname, 255, "%s", curr_entry->name); + snprintf(newname, sizeof(newname), "%s", curr_entry->name); if (ShowKeyboardOrPrompt(newname, 256, STR_RENAME_FILE_ENTER_NEW_NAME_BELOW, namestr)) { if (!PathRename(curr_entry->path, newname)) ShowPrompt(false, STR_FAILED_RENAMING_PATH, namestr); @@ -2889,7 +2888,7 @@ u32 GodMode(int entrypoint) { if (type) { char ename[256]; u64 fsize = 0; - snprintf(ename, 255, (type == 1) ? "newdir" : "dummy.bin"); + snprintf(ename, sizeof(ename), (type == 1) ? "newdir" : "dummy.bin"); if ((ShowKeyboardOrPrompt(ename, 256, "%s", (type == 1) ? STR_CREATE_NEW_FOLDER_HERE_ENTER_NAME_BELOW : STR_CREATE_NEW_FILE_HERE_ENTER_NAME_BELOW)) && ((type != 2) || ((fsize = ShowNumberPrompt(0, "%s", STR_CREATE_NEW_FILE_HERE_ENTER_SIZE_BELOW)) != (u64) -1))) { if (((type == 1) && !DirCreate(current_path, ename)) || @@ -2956,7 +2955,7 @@ u32 GodMode(int entrypoint) { const char* tpath = tmpaths[tmnum-1]; if (InitImgFS(tpath)) { SetTitleManagerMode(true); - snprintf(current_path, 256, "Y:"); + snprintf(current_path, sizeof(current_path), "Y:"); GetDirContents(current_dir, current_path); ClearScreenF(true, true, COLOR_STD_BG); cursor = 1; @@ -3090,7 +3089,7 @@ u32 ScriptRunner(int entrypoint) { } else if (PathExist("V:/" VRAM0_SCRIPTS)) { char loadpath[256]; char title[256]; - snprintf(title, 256, STR_FLAVOR_SCRIPTS_MENU_SELECT_SCRIPT, FLAVOR); + snprintf(title, sizeof(title), STR_FLAVOR_SCRIPTS_MENU_SELECT_SCRIPT, FLAVOR); if (FileSelector(loadpath, title, "V:/" VRAM0_SCRIPTS, "*.gm9", HIDE_EXT, false)) ExecuteGM9Script(loadpath); } else ShowPrompt(false, STR_COMPILED_AS_SCRIPT_AUTORUNNER_BUT_NO_SCRIPT_DERP); diff --git a/arm9/source/language.c b/arm9/source/language.c index 0bd2c9b..d8cb65d 100644 --- a/arm9/source/language.c +++ b/arm9/source/language.c @@ -138,10 +138,10 @@ const void* GetLanguage(const void* riff, const u32 riff_size, u32* version, u32 return NULL; } -int compLanguage(const void *e1, const void *e2) { - const Language *entry2 = (const Language *) e2; - const Language *entry1 = (const Language *) e1; - return strncasecmp(entry1->name, entry2->name, 256); +int compLanguage(const void* e1, const void* e2) { + const Language* entry2 = (const Language*) e2; + const Language* entry1 = (const Language*) e1; + return strncasecmp(entry1->name, entry2->name, 32); } bool LanguageMenu(char* result, const char* title) { diff --git a/arm9/source/system/xrq.c b/arm9/source/system/xrq.c index a2d0029..c8367f2 100644 --- a/arm9/source/system/xrq.c +++ b/arm9/source/system/xrq.c @@ -138,7 +138,7 @@ void XRQ_DumpRegisters(u32 xrq, u32 *regs) /* Dump to SD */ char path[64]; - snprintf(path, 64, "%s/exception_dump_%02lX%02lX%02lX%02lX%02lX%02lX.txt", OUTPUT_PATH, + snprintf(path, sizeof(path), "%s/exception_dump_%02lX%02lX%02lX%02lX%02lX%02lX.txt", OUTPUT_PATH, (u32) dstime.bcd_Y, (u32) dstime.bcd_M, (u32) dstime.bcd_D, (u32) dstime.bcd_h, (u32) dstime.bcd_m, (u32) dstime.bcd_s); ResizeString(tempstr, STR_DUMPING_STATE_TO_SD_CARD, 29, 29, false); diff --git a/arm9/source/utils/ctrtransfer.c b/arm9/source/utils/ctrtransfer.c index d81d789..3f7177d 100644 --- a/arm9/source/utils/ctrtransfer.c +++ b/arm9/source/utils/ctrtransfer.c @@ -64,11 +64,11 @@ u32 TransferCtrNandImage(const char* path_img, const char* drv) { char path_tickdb[32]; char path_tickdb_bak[32]; - snprintf(path_secnfo_a, 32, "%s/rw/sys/SecureInfo_A", drv); - snprintf(path_secnfo_b, 32, "%s/rw/sys/SecureInfo_B", drv); - snprintf(path_secnfo_c, 32, "%s/rw/sys/SecureInfo_C", drv); - snprintf(path_tickdb, 32, "%s/dbs/ticket.db", drv); - snprintf(path_tickdb_bak, 32, "%s/dbs/ticket.bak", drv); + snprintf(path_secnfo_a, sizeof(path_secnfo_a), "%s/rw/sys/SecureInfo_A", drv); + snprintf(path_secnfo_b, sizeof(path_secnfo_b), "%s/rw/sys/SecureInfo_B", drv); + snprintf(path_secnfo_c, sizeof(path_secnfo_c), "%s/rw/sys/SecureInfo_C", drv); + snprintf(path_tickdb, sizeof(path_tickdb), "%s/dbs/ticket.db", drv); + snprintf(path_tickdb_bak, sizeof(path_tickdb_bak), "%s/dbs/ticket.bak", drv); // special handling for out of region images (create SecureInfo_C) PathDelete(path_secnfo_c); // not required when transfering back to original region @@ -88,11 +88,11 @@ u32 TransferCtrNandImage(const char* path_img, const char* drv) { char path_movable[32]; char path_asr[96]; u8 sd_keyy[0x10] __attribute__((aligned(4))); - snprintf(path_movable, 32, "%s/private/movable.sed", drv); + snprintf(path_movable, sizeof(path_movable), "%s/private/movable.sed", drv); if (FileGetData(path_movable, sd_keyy, 0x10, 0x110) == 0x10) { u32 sha256sum[8]; sha_quick(sha256sum, sd_keyy, 0x10, SHA256_MODE); - snprintf(path_asr, 96, "%s/data/%08lx%08lx%08lx%08lx/sysdata/00010011/00000000", + snprintf(path_asr, sizeof(path_asr), "%s/data/%08lx%08lx%08lx%08lx/sysdata/00010011/00000000", drv, sha256sum[0], sha256sum[1], sha256sum[2], sha256sum[3]); PathDelete(path_asr); } @@ -103,17 +103,17 @@ u32 TransferCtrNandImage(const char* path_img, const char* drv) { char path_from[32]; char path_dbs[32]; u32 flags = OVERWRITE_ALL; - snprintf(path_dbs, 32, "%s/dbs", drv); + snprintf(path_dbs, sizeof(path_dbs), "%s/dbs", drv); for (u32 i = 0; i < sizeof(dbnames) / sizeof(char*); i++) { - snprintf(path_to, 32, "%s/dbs/%s", drv, dbnames[i]); - snprintf(path_from, 32, "7:/dbs/%s", dbnames[i]); + snprintf(path_to, sizeof(path_to), "%s/dbs/%s", drv, dbnames[i]); + snprintf(path_from, sizeof(path_from), "7:/dbs/%s", dbnames[i]); PathDelete(path_to); PathCopy(path_dbs, path_from, &flags); FixFileCmac(path_to, true); } ShowString("%s", STR_CLEANING_UP_TITLES_PLEASE_WAIT); - snprintf(path_to, 32, "%s/title", drv); - snprintf(path_from, 32, "7:/title"); + snprintf(path_to, sizeof(path_to), "%s/title", drv); + snprintf(path_from, sizeof(path_from), "7:/title"); PathDelete(path_to); PathCopy(drv, path_from, &flags); diff --git a/arm9/source/utils/gameutil.c b/arm9/source/utils/gameutil.c index 223e1b9..ded8852 100644 --- a/arm9/source/utils/gameutil.c +++ b/arm9/source/utils/gameutil.c @@ -294,7 +294,7 @@ u32 LoadCdnTicketFile(Ticket** ticket, const char* path_cnt) { char* name_cetk = strrchr(path_cetk, '/'); if (!name_cetk) return 1; // will not happen name_cetk++; - snprintf(name_cetk, 256 - (name_cetk - path_cetk), "cetk"); + snprintf(name_cetk, sizeof(path_cetk) - (name_cetk - path_cetk), "cetk"); // ticket is loaded and validated here return LoadTicketFile(ticket, path_cetk); } @@ -335,7 +335,7 @@ u32 GetTmdContentPath(char* path_content, const char* path_tmd) { // content path string char* name_content; - snprintf(path_content, 255, "%s", path_tmd); + snprintf(path_content, 256, "%s", path_tmd); path_content[255] = '\0'; name_content = strrchr(path_content, '/'); if (!name_content) return 1; // will not happen @@ -352,7 +352,7 @@ u32 GetTmdContentPath(char* path_content, const char* path_tmd) { free(tmd); return 1; } - snprintf(name_content, 255 - (name_content - path_content), cdn ? "%08lx" : + snprintf(name_content, 256 - (name_content - path_content), cdn ? "%08lx" : (memcmp(tmd->title_id, dlc_tid_high, sizeof(dlc_tid_high)) == 0) ? "00000000/%08lx.app" : "%08lx.app", getbe32(chunk->id)); free(tmd); @@ -418,7 +418,7 @@ u32 GetTitleIdTmdPath(char* path_tmd, const u64 title_id, bool from_emunand) { if (tid_high & 0x8000) tid_high = 0x00030000 | (tid_high&0xFF); char path_pat[64]; - snprintf(path_pat, 64, "%2.2s/title/%08lX/%08lX/content/*.tmd", + snprintf(path_pat, sizeof(path_pat), "%2.2s/title/%08lX/%08lX/content/*.tmd", drv, tid_high, tid_low); if (fvx_findpath(path_tmd, path_pat, FN_HIGHEST) != FR_OK) diff --git a/arm9/source/utils/nandcmac.c b/arm9/source/utils/nandcmac.c index 92f57ea..ab749af 100644 --- a/arm9/source/utils/nandcmac.c +++ b/arm9/source/utils/nandcmac.c @@ -59,7 +59,7 @@ u32 SetupSlot0x30(char drv) { if ((drv == 'A') || (drv == 'S')) drv = '1'; else if ((drv == 'B') || (drv == 'E')) drv = '4'; - snprintf(movable_path, 32, "%c:/private/movable.sed", drv); + snprintf(movable_path, sizeof(movable_path), "%c:/private/movable.sed", drv); if (fvx_qread(movable_path, keyy, 0x110, 0x10, NULL) != FR_OK) return 1; setup_aeskeyY(0x30, keyy); use_aeskey(0x30); diff --git a/arm9/source/utils/nandutil.c b/arm9/source/utils/nandutil.c index 7829322..785ff32 100644 --- a/arm9/source/utils/nandutil.c +++ b/arm9/source/utils/nandutil.c @@ -150,7 +150,7 @@ u32 DumpGbaVcSavegameBuffered(const char* path, void* buffer) { // generate output path char path_vcsav[64]; - snprintf(path_vcsav, 64, OUTPUT_PATH "/%016llX.gbavc.sav", agbsave->title_id); + snprintf(path_vcsav, sizeof(path_vcsav), OUTPUT_PATH "/%016llX.gbavc.sav", agbsave->title_id); if (fvx_qwrite(path_vcsav, savegame, 0, agbsave->save_size, NULL) != FR_OK) return 1; // write fail return 0; @@ -207,7 +207,7 @@ u32 InjectGbaVcSavegameBuffered(const char* path, const char* path_vcsave, void* u32 slot = 0; // get the SD save path, check SD save size - snprintf(path_sd, 64, "A:/title/%08lx/%08lx/data/00000001.sav", + snprintf(path_sd, sizeof(path_sd), "A:/title/%08lx/%08lx/data/00000001.sav", getle32((u8*) &(agbsave->title_id) + 4), getle32((u8*) &(agbsave->title_id))); if ((fvx_stat(path_sd, &fno) != FR_OK) || (fno.fsize != max(AGBSAVE_MAX_SIZE, 2 * data_size))) return 1; // invalid / non-existant SD save diff --git a/arm9/source/utils/scripting.c b/arm9/source/utils/scripting.c index c80657b..0c7dbdc 100644 --- a/arm9/source/utils/scripting.c +++ b/arm9/source/utils/scripting.c @@ -422,7 +422,7 @@ void upd_var(const char* name) { if (FileGetData(path, sd_keyy, 0x10, 0x110) == 0x10) { u32 sha256sum[8]; sha_quick(sha256sum, sd_keyy, 0x10, SHA256_MODE); - snprintf(env_id0, 32+1, "%08lx%08lx%08lx%08lx", + snprintf(env_id0, sizeof(env_id0), "%08lx%08lx%08lx%08lx", sha256sum[0], sha256sum[1], sha256sum[2], sha256sum[3]); } else snprintf(env_id0, 0xF, "UNKNOWN"); set_var(env_id0_name, env_id0); @@ -435,8 +435,8 @@ void upd_var(const char* name) { get_dstime(&dstime); char env_date[16+1]; char env_time[16+1]; - 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); + snprintf(env_date, sizeof(env_date), "%02lX%02lX%02lX", (u32) dstime.bcd_Y, (u32) dstime.bcd_M, (u32) dstime.bcd_D); + snprintf(env_time, sizeof(env_time), "%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); } @@ -445,7 +445,7 @@ void upd_var(const char* name) { if (!name || (strncmp(name, "EMUBASE", _VAR_NAME_LEN) == 0)) { u32 emu_base = GetEmuNandBase(); char emu_base_str[8+1]; - snprintf(emu_base_str, 8+1, "%08lX", emu_base); + snprintf(emu_base_str, sizeof(emu_base_str), "%08lX", emu_base); set_var("EMUBASE", emu_base_str); } @@ -781,8 +781,8 @@ bool for_handler(char* path, const char* dir, const char* pattern, bool recursiv } if (dir) { // open a dir - snprintf(lpattern, 64, "%s", pattern); - snprintf(ldir, 256, "%s", dir); + snprintf(lpattern, sizeof(lpattern), "%s", pattern); + snprintf(ldir, sizeof(ldir), "%s", dir); if (dp) return false; // <- this should never happen if (fvx_opendir(&fdir[0], dir) != FR_OK) return false; @@ -1318,10 +1318,10 @@ bool run_cmd(cmd_id id, u32 flags, char** argv, char* err_str) { } else if (!strchr(argv[1], ':')) { char hash_str[64+1]; if (flags & _FLG('1')) - snprintf(hash_str, 64+1, "%016llX%016llX%08lX", getbe64(hash_fil + 0), getbe64(hash_fil + 8), + snprintf(hash_str, sizeof(hash_str), "%016llX%016llX%08lX", getbe64(hash_fil + 0), getbe64(hash_fil + 8), getbe32(hash_fil + 16)); else - snprintf(hash_str, 64+1, "%016llX%016llX%016llX%016llX", getbe64(hash_fil + 0), getbe64(hash_fil + 8), + snprintf(hash_str, sizeof(hash_str), "%016llX%016llX%016llX%016llX", getbe64(hash_fil + 0), getbe64(hash_fil + 8), getbe64(hash_fil + 16), getbe64(hash_fil + 24)); ret = set_var(argv[1], hash_str); if (err_str) snprintf(err_str, _ERR_STR_LEN, "%s", STR_SCRIPTERR_VAR_FAIL); @@ -1487,7 +1487,7 @@ bool run_cmd(cmd_id id, u32 flags, char** argv, char* err_str) { if (ret) { char fixpath[256] = { 0 }; if ((*argv[0] == '0') || (*argv[0] == '1')) - snprintf(fixpath, 256, "%s%s", (*argv[0] == '0') ? "sdmc" : "nand", argv[0] + 1); + snprintf(fixpath, sizeof(fixpath), "%s%s", (*argv[0] == '0') ? "sdmc" : "nand", argv[0] + 1); else strncpy(fixpath, argv[0], 256); fixpath[255] = '\0'; DeinitExtFS(); @@ -1658,7 +1658,7 @@ void MemTextView(const char* text, u32 len, char* line0, int off_disp, int lno, if (cmt_start <= 0) color_text = script_color_comment; // build text string - snprintf(txtstr, TV_LLEN_DISP + 1, "%-*.*s", (int) TV_LLEN_DISP, (int) TV_LLEN_DISP, ""); + snprintf(txtstr, sizeof(txtstr), "%-*.*s", (int) TV_LLEN_DISP, (int) TV_LLEN_DISP, ""); if (ncpy) memcpy(txtstr, ptr + off_disp, ncpy); for (char* d = txtstr; *d; d++) if (*d < ' ') *d = ' '; if (al) memcpy(txtstr + p_al, al_str, strnlen(al_str, 16)); @@ -2024,8 +2024,8 @@ bool ExecuteGM9Script(const char* path_script) { char* lptr1 = line_end; for (; IS_WHITESPACE(*lptr0) && (lptr0 < lptr1); lptr0++); // skip whitespaces if ((lptr1 > lptr0) && (*(lptr1-1) == '\r')) lptr1--; // handle \r - if (lptr1 - lptr0 > 32) snprintf(line_str, 32+1, "%.29s...", lptr0); - else snprintf(line_str, 32+1, "%.*s", lptr1 - lptr0, lptr0); + if (lptr1 - lptr0 > 32) snprintf(line_str, sizeof(line_str), "%.29s...", lptr0); + else snprintf(line_str, sizeof(line_str), "%.*s", lptr1 - lptr0, lptr0); ShowPrompt(false, STR_PATH_LINE_N_ERR_LINE, path_str, lno, err_str, line_str); } } diff --git a/arm9/source/virtual/vkeydb.c b/arm9/source/virtual/vkeydb.c index 1ae7f0a..b3d8973 100644 --- a/arm9/source/virtual/vkeydb.c +++ b/arm9/source/virtual/vkeydb.c @@ -53,11 +53,11 @@ bool ReadVKeyDbDir(VirtualFile* vfile, VirtualDir* vdir) { if (++vdir->index < (int) n_keys) { AesKeyInfo* key_entry = key_info + vdir->index; u32 keyslot = key_entry->slot; - char typestr[16] = { 0 }; + char typestr[16]; char* unitext = (key_entry->keyUnitType == KEYS_DEVKIT) ? ".dev" : (key_entry->keyUnitType == KEYS_RETAIL) ? ".ret" : ""; - snprintf(typestr, 12 + 1, "%s%.10s", (key_entry->type == 'I') ? "IV" : + snprintf(typestr, sizeof(typestr), "%s%.10s", (key_entry->type == 'I') ? "IV" : (key_entry->type == 'X') ? "X" : (key_entry->type == 'Y') ? "Y" : "", key_entry->id); memset(vfile, 0, sizeof(VirtualFile));