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
This commit is contained in:
Dave Murphy 2018-05-08 19:58:38 +00:00 committed by fincs
parent 6f248b9b9e
commit e648524fa5
3 changed files with 6 additions and 4 deletions

View File

@ -200,6 +200,7 @@ fsdev_fixpath(struct _reent *r,
else else
{ {
strncpy(__fixedpath, __cwd, PATH_MAX); strncpy(__fixedpath, __cwd, PATH_MAX);
__fixedpath[PATH_MAX] = '\0';
strncat(__fixedpath, path, PATH_MAX - strlen(__cwd)); strncat(__fixedpath, path, PATH_MAX - strlen(__cwd));
} }
@ -241,8 +242,8 @@ fsdev_getfspath(struct _reent *r,
if(fsdev_fixpath(r, path, device) == NULL) if(fsdev_fixpath(r, path, device) == NULL)
return -1; return -1;
memset(outpath, 0, FS_MAX_PATH); memcpy(outpath, __fixedpath,FS_MAX_PATH-1);
strncpy(outpath, __fixedpath, FS_MAX_PATH); outpath[FS_MAX_PATH-1] = '\0';
return 0; return 0;
} }
@ -1039,6 +1040,7 @@ fsdev_chdir(struct _reent *r,
{ {
fsDirClose(&fd); fsDirClose(&fd);
strncpy(__cwd, __fixedpath, PATH_MAX); strncpy(__cwd, __fixedpath, PATH_MAX);
__cwd[PATH_MAX] = '\0';
fsdev_fsdevice_cwd = device->id; fsdev_fsdevice_cwd = device->id;
return 0; return 0;
} }

View File

@ -36,7 +36,7 @@ void fsldrExit(void) {
} }
Result fsldrOpenCodeFileSystem(u64 tid, const char *path, FsFileSystem* out) { 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; IpcCommand c;
ipcInitialize(&c); ipcInitialize(&c);
ipcAddSendStatic(&c, send_path, FS_MAX_PATH, 0); ipcAddSendStatic(&c, send_path, FS_MAX_PATH, 0);

View File

@ -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. 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) { 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; IpcCommand c;
ipcInitialize(&c); ipcInitialize(&c);
ipcAddSendStatic(&c, send_path, FS_MAX_PATH, 0); ipcAddSendStatic(&c, send_path, FS_MAX_PATH, 0);