fixed minor gcc warning
gcc-8 on Linux doesn't like usage of strncat : `warning: ‘strncat’ output truncated before terminating nul copying as many bytes from a string as its length`. Not sure what was wrong, it might be a false positive, but the logic is simple enough to replaced by a simple `memcpy()`, thus avoiding the shenanigans of null-terminated strings.
This commit is contained in:
+4
-3
@@ -1219,7 +1219,8 @@ FIO_determineCompressedName(const char* srcFileName, const char* suffix)
|
|||||||
size_t const sfnSize = strlen(srcFileName);
|
size_t const sfnSize = strlen(srcFileName);
|
||||||
size_t const suffixSize = strlen(suffix);
|
size_t const suffixSize = strlen(suffix);
|
||||||
|
|
||||||
if (dfnbCapacity <= sfnSize+suffixSize+1) { /* resize name buffer */
|
if (dfnbCapacity <= sfnSize+suffixSize+1) {
|
||||||
|
/* resize buffer for dstName */
|
||||||
free(dstFileNameBuffer);
|
free(dstFileNameBuffer);
|
||||||
dfnbCapacity = sfnSize + suffixSize + 30;
|
dfnbCapacity = sfnSize + suffixSize + 30;
|
||||||
dstFileNameBuffer = (char*)malloc(dfnbCapacity);
|
dstFileNameBuffer = (char*)malloc(dfnbCapacity);
|
||||||
@@ -1227,8 +1228,8 @@ FIO_determineCompressedName(const char* srcFileName, const char* suffix)
|
|||||||
EXM_THROW(30, "zstd: %s", strerror(errno));
|
EXM_THROW(30, "zstd: %s", strerror(errno));
|
||||||
} }
|
} }
|
||||||
assert(dstFileNameBuffer != NULL);
|
assert(dstFileNameBuffer != NULL);
|
||||||
strncpy(dstFileNameBuffer, srcFileName, sfnSize+1 /* Include null */);
|
memcpy(dstFileNameBuffer, srcFileName, sfnSize);
|
||||||
strncat(dstFileNameBuffer, suffix, suffixSize);
|
memcpy(dstFileNameBuffer+sfnSize, suffix, suffixSize+1 /* Include terminating null */);
|
||||||
|
|
||||||
return dstFileNameBuffer;
|
return dstFileNameBuffer;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user