Merge pull request #1366 from facebook/fix_strncat

fixed minor gcc warning
This commit is contained in:
Yann Collet 2018-10-11 14:58:00 -07:00 committed by GitHub
commit 02e5c03f24
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1219,7 +1219,8 @@ FIO_determineCompressedName(const char* srcFileName, const char* suffix)
size_t const sfnSize = strlen(srcFileName);
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);
dfnbCapacity = sfnSize + suffixSize + 30;
dstFileNameBuffer = (char*)malloc(dfnbCapacity);
@ -1227,8 +1228,8 @@ FIO_determineCompressedName(const char* srcFileName, const char* suffix)
EXM_THROW(30, "zstd: %s", strerror(errno));
} }
assert(dstFileNameBuffer != NULL);
strncpy(dstFileNameBuffer, srcFileName, sfnSize+1 /* Include null */);
strncat(dstFileNameBuffer, suffix, suffixSize);
memcpy(dstFileNameBuffer, srcFileName, sfnSize);
memcpy(dstFileNameBuffer+sfnSize, suffix, suffixSize+1 /* Include terminating null */);
return dstFileNameBuffer;
}