summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYann Collet <yann.collet.73@gmail.com>2019-04-19 00:26:01 (GMT)
committerYann Collet <yann.collet.73@gmail.com>2019-04-19 00:26:01 (GMT)
commit4e4f1ad623cca9ebd212400b5783c63fd76dc868 (patch)
treee478d0f39485c63e3dc246124aa7c7ed954bf034
parent4790994568d4d3ba492857c4c567ea6517588a45 (diff)
downloadlz4-4e4f1ad623cca9ebd212400b5783c63fd76dc868.zip
lz4-4e4f1ad623cca9ebd212400b5783c63fd76dc868.tar.gz
lz4-4e4f1ad623cca9ebd212400b5783c63fd76dc868.tar.bz2
ensure list of names is large enough
-rw-r--r--programs/util.h19
1 files changed, 9 insertions, 10 deletions
diff --git a/programs/util.h b/programs/util.h
index 6a35481..1dd515c 100644
--- a/programs/util.h
+++ b/programs/util.h
@@ -379,7 +379,7 @@ UTIL_STATIC U64 UTIL_getTotalFileSize(const char** fileNamesTable, unsigned nbFi
*/
UTIL_STATIC void* UTIL_realloc(void* ptr, size_t size)
{
- void* newptr = realloc(ptr, size);
+ void* const newptr = realloc(ptr, size);
if (newptr) return newptr;
free(ptr);
return NULL;
@@ -529,7 +529,8 @@ UTIL_STATIC int UTIL_prepareFileList(const char* dirName, char** bufStart, size_
* In case of error UTIL_createFileList returns NULL and UTIL_freeFileList should not be called.
*/
UTIL_STATIC const char**
-UTIL_createFileList(const char** inputNames, unsigned inputNamesNb, char** allocatedBuffer, unsigned* allocatedNamesNb)
+UTIL_createFileList(const char** inputNames, unsigned inputNamesNb,
+ char** allocatedBuffer, unsigned* allocatedNamesNb)
{
size_t pos;
unsigned i, nbFiles;
@@ -543,16 +544,14 @@ UTIL_createFileList(const char** inputNames, unsigned inputNamesNb, char** alloc
if (!UTIL_isDirectory(inputNames[i])) {
size_t const len = strlen(inputNames[i]);
if (pos + len >= bufSize) {
- size_t newListSize = bufSize + LIST_SIZE_INCREASE;
- buf = (char*)UTIL_realloc(buf, newListSize);
- bufSize = newListSize;
+ while (pos + len >= bufSize) bufSize += LIST_SIZE_INCREASE;
+ buf = (char*)UTIL_realloc(buf, bufSize);
if (!buf) return NULL;
}
- if (pos + len < bufSize) {
- strncpy(buf + pos, inputNames[i], bufSize - pos);
- pos += len + 1;
- nbFiles++;
- }
+ assert(pos + len < bufSize);
+ strncpy(buf + pos, inputNames[i], bufSize - pos);
+ pos += len + 1;
+ nbFiles++;
} else {
char* bufend = buf + bufSize;
nbFiles += (unsigned)UTIL_prepareFileList(inputNames[i], &buf, &pos, &bufend);