Skip to content

Commit

Permalink
Misc code improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
d0k3 committed Feb 5, 2021
1 parent 58fb991 commit e41b098
Show file tree
Hide file tree
Showing 9 changed files with 16 additions and 9 deletions.
2 changes: 1 addition & 1 deletion arm9/source/common/ui.c
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,7 @@ u32 ShowFileScrollPrompt(u32 n, const DirEntry** options, bool hide_ext, const c

char content_str[64 + 1];
char temp_str[256];
strncpy(temp_str, options[i]->name, 255);
strncpy(temp_str, options[i]->name, 256);

char* dot = strrchr(temp_str, '.');
if (hide_ext && dot) *dot = '\0';
Expand Down
5 changes: 3 additions & 2 deletions arm9/source/filesys/fsutil.c
Original file line number Diff line number Diff line change
Expand Up @@ -606,8 +606,8 @@ bool PathMoveCopy(const char* dest, const char* orig, u32* flags, bool move) {
int odrvtype = DriveType(orig);
char ldest[256]; // 256 is the maximum length of a full path
char lorig[256];
strncpy(ldest, dest, 255);
strncpy(lorig, orig, 255);
strncpy(ldest, dest, 256);
strncpy(lorig, orig, 256);
char deststr[36 + 1];
TruncateString(deststr, ldest, 36, 8);

Expand Down Expand Up @@ -883,6 +883,7 @@ bool FileSelector(char* result, const char* text, const char* path, const char*
void* buffer = (void*) malloc(sizeof(DirStruct));
if (!buffer) return false;

// for this to work, result needs to be at least 256 bytes in size
bool ret = FileSelectorWorker(result, text, path, pattern, flags, buffer, new_style);
free(buffer);
return ret;
Expand Down
2 changes: 1 addition & 1 deletion arm9/source/filesys/image.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,6 @@ u64 MountImage(const char* path) {
return 0;
fvx_lseek(&mount_file, 0);
fvx_sync(&mount_file);
strncpy(mount_path, path, 255);
strncpy(mount_path, path, 256);
return (mount_state = type);
}
4 changes: 2 additions & 2 deletions arm9/source/filesys/sddata.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ int alias_num (const TCHAR* path) {
void dealias_path (TCHAR* alias, const TCHAR* path) {
int num = alias_num(path);
u32 p_offs = (path[2] == '/' && ((path[3] == '/') || (path[3] == '\0'))) ? 3 : 2;
if (num >= 0) // set alias (alias is assumed to be 256 byte)
if (num >= 0) // set alias (alias is assumed to be 256 byte!)
snprintf(alias, 256, "%s%s", alias_path[num], path + p_offs);
else strncpy(alias, path, 256);
else snprintf(alias, 256, "%s", path);
}

FilCryptInfo* fx_find_cryptinfo(FIL* fptr) {
Expand Down
1 change: 1 addition & 0 deletions arm9/source/filesys/support.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ bool CheckSupportDir(const char* dname)
bool FileSelectorSupport(char* result, const char* text, const char* dname, const char* pattern)
{
char path[256];
// result needs to be at least 256 bytes long for this to work!
if (!GetSupportDir(path, dname)) return false;
return FileSelector(result, text, path, pattern, HIDE_EXT, false);
}
2 changes: 1 addition & 1 deletion arm9/source/godmode.c
Original file line number Diff line number Diff line change
Expand Up @@ -2194,7 +2194,7 @@ u32 GodMode(int entrypoint) {
const u32 quick_stp = (MAIN_SCREEN == TOP_SCREEN) ? 20 : 19;
u32 exit_mode = GODMODE_EXIT_POWEROFF;

char current_path[256] = { 0x00 };
char current_path[256] = { 0x00 }; // don't change this size!
u32 cursor = 0;
u32 scroll = 0;

Expand Down
6 changes: 5 additions & 1 deletion arm9/source/utils/gameutil.c
Original file line number Diff line number Diff line change
Expand Up @@ -238,12 +238,14 @@ u32 LoadCdnTicketFile(Ticket** ticket, const char* path_cnt) {
}

u32 GetTmdContentPath(char* path_content, const char* path_tmd) {
// path_content should be 256 bytes in size!

// get path to TMD first content
static const u8 dlc_tid_high[] = { DLC_TID_HIGH };

// content path string
char* name_content;
strncpy(path_content, path_tmd, 256);
snprintf(path_content, 255, "%s", path_tmd);
path_content[255] = '\0';
name_content = strrchr(path_content, '/');
if (!name_content) return 1; // will not happen
Expand Down Expand Up @@ -2450,6 +2452,8 @@ u32 ExtractCodeFromCxiFile(const char* path, const char* path_out, char* extstr)
dest[255] = '\0';
if (!CheckWritePermissions(dest)) return 1;

// extstr should be at least 16 bytes in size

// NCSD handling
u32 ncch_offset = 0;
if (filetype & GAME_NCSD) {
Expand Down
2 changes: 1 addition & 1 deletion arm9/source/utils/scripting.c
Original file line number Diff line number Diff line change
Expand Up @@ -774,7 +774,7 @@ bool for_handler(char* path, const char* dir, const char* pattern, bool recursiv
snprintf(path, 256, "%s/%.254s", ldir, fno.fname);
if (rec && (fno.fattrib & AM_DIR) && (dp - fdir < _MAX_FOR_DEPTH - 1)) {
if (fvx_opendir(++dp, path) != FR_OK) dp--;
else strncpy(ldir, path, 255);
else strncpy(ldir, path, 256);
}
} else return false;

Expand Down
1 change: 1 addition & 0 deletions arm9/source/utils/sysinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ void GetSysInfo_SecureInfo(SysInfo* info, char nand_drive) {
// Determine the sub-model from the first two digits of the digit part.
if (first_digit && second_digit) {
if (IS_DEVKIT) {
// missing: identification for IS-CLOSER-BOX (issue #276)
if ((first_digit == '9') && (second_digit == '0') && (info->int_model == MODEL_OLD_3DS)) {
strncpy(info->sub_model, "Partner-CTR", countof("Partner-CTR"));
} else if ((first_digit == '9') && (second_digit == '1') && (info->int_model == MODEL_OLD_3DS)) {
Expand Down

0 comments on commit e41b098

Please sign in to comment.