diff --git a/include/util.h b/include/util.h index 1fd1c15..a2c4147 100644 --- a/include/util.h +++ b/include/util.h @@ -15,7 +15,7 @@ } // custom safe strncpy, string is always 0-terminated for buflen > 0 -static void strncpy_s(char *dest, char *src, u32 nchars, u32 buflen) +static void strncpy_s(char *dest, const char *src, u32 nchars, const u32 buflen) { char c; diff --git a/source/arm9/filebrowse.c b/source/arm9/filebrowse.c index e58448f..86a90ca 100644 --- a/source/arm9/filebrowse.c +++ b/source/arm9/filebrowse.c @@ -54,7 +54,7 @@ if(fno.fattrib & AM_DIR) // directory snprintf(dirEntries[curEntriesCount + i].name, _MAX_LFN + 1, "\\%s", fno.fname); else // file - strncpy(dirEntries[curEntriesCount + i].name, fno.fname, _MAX_LFN + 1); + strncpy_s(dirEntries[curEntriesCount + i].name, fno.fname, _MAX_LFN + 1, _MAX_LFN + 2); } curEntriesCount += i; @@ -159,9 +159,9 @@ if(!dirEntries) return NULL; if(basePath) - strncpy(curPath, basePath, sizeof(curPath)); + strncpy_s(curPath, basePath, sizeof(curPath) - 1, sizeof(curPath)); else - strncpy(curPath, "sdmc:", sizeof(curPath)); + strncpy_s(curPath, "sdmc:", sizeof(curPath) - 1, sizeof(curPath)); res = f_opendir(&curDirectory, curPath); if (res != FR_OK)