]> jfr.im git - irc/gunnarbeutner/shroudbnc.git/commitdiff
Fix Coverity warning about unsafe strncat() usage.
authorGunnar Beutner <redacted>
Wed, 5 Feb 2014 17:55:49 +0000 (18:55 +0100)
committerGunnar Beutner <redacted>
Thu, 6 Feb 2014 07:53:02 +0000 (08:53 +0100)
src/sbnc.cpp

index d701a764fb4b86db3ce55281c0a1598ef32dce61..8547e7529ce985e159ea3762053eb93b06f051e1 100644 (file)
@@ -208,18 +208,14 @@ const char *sbncBuildPath(const char *Filename, const char *ExePath) {
 
        free(Path);
 
-       Len = strlen(ExePath) + 1 + strlen(Filename) + 1;
-       Path = (char *)malloc(Len);
-       strncpy(Path, ExePath, Len);
-#ifdef _WIN32
-       strncat(Path, "\\", Len);
-#else
-       strncat(Path, "/", Len);
-#endif
-       strncat(Path, Filename, Len);
+       asprintf(&Path, "%s/%s", ExePath, Filename);
+
+       if (AllocFailed(Path)) {
+               return NULL;
+       }
 
 #ifdef _WIN32
-       for (unsigned int i = 0; i < strlen(Path); i++) {
+       for (unsigned int i = 0; Path[i] != '\0'; i++) {
                if (Path[i] == '/') {
                        Path[i] = '\\';
                }