diff options
author | Ulrich Sibiller <uli42@gmx.de> | 2017-12-28 11:19:44 +0100 |
---|---|---|
committer | Ulrich Sibiller <uli42@gmx.de> | 2017-12-29 02:31:27 +0100 |
commit | 6e98e35cf24016c9789be26d33d918f6e0e3c9a1 (patch) | |
tree | 96add1b357be3fdef7eb669691a59e1cf6fc06f7 /nxcomp/src/Children.cpp | |
parent | 9e8bd2e1b6029ef04dec424fefcdf8842a0daf0f (diff) | |
download | nx-libs-6e98e35cf24016c9789be26d33d918f6e0e3c9a1.tar.gz nx-libs-6e98e35cf24016c9789be26d33d918f6e0e3c9a1.tar.bz2 nx-libs-6e98e35cf24016c9789be26d33d918f6e0e3c9a1.zip |
nxcomp: drop strncpy in favour of snprintf
with very few exceptions which require careful thinking ;-)
Diffstat (limited to 'nxcomp/src/Children.cpp')
-rw-r--r-- | nxcomp/src/Children.cpp | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/nxcomp/src/Children.cpp b/nxcomp/src/Children.cpp index 9486f189a..e586292da 100644 --- a/nxcomp/src/Children.cpp +++ b/nxcomp/src/Children.cpp @@ -275,12 +275,14 @@ int NXTransDialog(const char *caption, const char *message, #ifdef __APPLE__ + // FIXME: missing length limitation! strcat(newPath, "/Applications/NX Client for OSX.app/Contents/MacOS:"); #endif #ifdef __CYGWIN32__ + // FIXME: missing length limitation! strcat(newPath, ".:"); #endif @@ -289,9 +291,8 @@ int NXTransDialog(const char *caption, const char *message, char *oldPath = getenv("PATH"); - strncpy(newPath + newLength, oldPath, DEFAULT_STRING_LIMIT - newLength - 1); - - newPath[DEFAULT_STRING_LIMIT - 1] = '\0'; + // FIXME: check if strncat would be better here + snprintf(newPath + newLength, DEFAULT_STRING_LIMIT - newLength, "%s", oldPath); #ifdef WARNING *logofs << "NXTransDialog: WARNING! Trying with path '" @@ -427,17 +428,13 @@ int NXTransClient(const char* display) #ifdef __sun - snprintf(newDisplay, DISPLAY_LENGTH_LIMIT - 1, "DISPLAY=%s", display); - - newDisplay[DISPLAY_LENGTH_LIMIT - 1] = '\0'; + snprintf(newDisplay, DISPLAY_LENGTH_LIMIT, "DISPLAY=%s", display); putenv(newDisplay); #else - strncpy(newDisplay, display, DISPLAY_LENGTH_LIMIT - 1); - - newDisplay[DISPLAY_LENGTH_LIMIT - 1] = '\0'; + snprintf(newDisplay, DISPLAY_LENGTH_LIMIT, "%s", display); setenv("DISPLAY", newDisplay, 1); @@ -467,6 +464,7 @@ int NXTransClient(const char* display) if (i == 0) { + // FIXME: code dpulication: this whole block is duplicated in NXTransDialog strcpy(command, "nxclient"); char newPath[DEFAULT_STRING_LIMIT]; @@ -489,7 +487,8 @@ int NXTransClient(const char* display) char *oldPath = getenv("PATH"); - strncpy(newPath + newLength, oldPath, DEFAULT_STRING_LIMIT - newLength - 1); + // FIXME: check if strncat would be better here + snprintf(newPath + newLength, DEFAULT_STRING_LIMIT - newLength, "%s", oldPath); newPath[DEFAULT_STRING_LIMIT - 1] = '\0'; |