From: Yann Collet Date: Fri, 19 Apr 2019 00:26:01 +0000 (-0700) Subject: ensure list of names is large enough X-Git-Tag: upstream/1.9.3~3^2~7^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=4e4f1ad623cca9ebd212400b5783c63fd76dc868;p=platform%2Fupstream%2Flz4.git ensure list of names is large enough --- 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);