From e648524fa56122760c8a5c48ee2486c8300ca84d Mon Sep 17 00:00:00 2001 From: Dave Murphy Date: Tue, 8 May 2018 19:58:38 +0000 Subject: [PATCH] fix stringop-truncation warnings (#84) avoid gcc 8.1.0 diagnostics as per https://gcc.gnu.org/onlinedocs/gcc-8.1.0/gcc/Warning-Options.html#index-Wstringop-truncation --- nx/source/runtime/devices/fs_dev.c | 6 ++++-- nx/source/services/fsldr.c | 2 +- nx/source/services/lr.c | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/nx/source/runtime/devices/fs_dev.c b/nx/source/runtime/devices/fs_dev.c index a5883def..b49b9172 100644 --- a/nx/source/runtime/devices/fs_dev.c +++ b/nx/source/runtime/devices/fs_dev.c @@ -200,6 +200,7 @@ fsdev_fixpath(struct _reent *r, else { strncpy(__fixedpath, __cwd, PATH_MAX); + __fixedpath[PATH_MAX] = '\0'; strncat(__fixedpath, path, PATH_MAX - strlen(__cwd)); } @@ -241,8 +242,8 @@ fsdev_getfspath(struct _reent *r, if(fsdev_fixpath(r, path, device) == NULL) return -1; - memset(outpath, 0, FS_MAX_PATH); - strncpy(outpath, __fixedpath, FS_MAX_PATH); + memcpy(outpath, __fixedpath,FS_MAX_PATH-1); + outpath[FS_MAX_PATH-1] = '\0'; return 0; } @@ -1039,6 +1040,7 @@ fsdev_chdir(struct _reent *r, { fsDirClose(&fd); strncpy(__cwd, __fixedpath, PATH_MAX); + __cwd[PATH_MAX] = '\0'; fsdev_fsdevice_cwd = device->id; return 0; } diff --git a/nx/source/services/fsldr.c b/nx/source/services/fsldr.c index a62b73bb..5e978f6a 100644 --- a/nx/source/services/fsldr.c +++ b/nx/source/services/fsldr.c @@ -36,7 +36,7 @@ void fsldrExit(void) { } Result fsldrOpenCodeFileSystem(u64 tid, const char *path, FsFileSystem* out) { - char send_path[FS_MAX_PATH] = {0}; + char send_path[FS_MAX_PATH+1] = {0}; IpcCommand c; ipcInitialize(&c); ipcAddSendStatic(&c, send_path, FS_MAX_PATH, 0); diff --git a/nx/source/services/lr.c b/nx/source/services/lr.c index 5fd49d97..d1499b7d 100644 --- a/nx/source/services/lr.c +++ b/nx/source/services/lr.c @@ -144,7 +144,7 @@ static Result _lrResolvePath(Service* s, u64 cmd_id, u64 tid, char *out) { This is a helper function to perform the work for those funcs, given a command ID. */ static Result _lrRedirectPath(Service* s, u64 cmd_id, u64 tid, const char *path) { - char send_path[FS_MAX_PATH] = {0}; + char send_path[FS_MAX_PATH+1] = {0}; IpcCommand c; ipcInitialize(&c); ipcAddSendStatic(&c, send_path, FS_MAX_PATH, 0);