diff options
author | Yann Collet <cyan@fb.com> | 2019-04-13 22:55:33 (GMT) |
---|---|---|
committer | Yann Collet <cyan@fb.com> | 2019-04-13 22:55:33 (GMT) |
commit | 321506974125cb3eeca89c2ca6abb5f3e9e497e2 (patch) | |
tree | 266f4a6dc77586e41d7d6cff6a388412463bd103 /programs/util.h | |
parent | 749c3400bd6ff6b49641fadaf0edb23d7a7b6413 (diff) | |
parent | cffde7eeb98304c490c4d235672452324e71fbc1 (diff) | |
download | lz4-321506974125cb3eeca89c2ca6abb5f3e9e497e2.zip lz4-321506974125cb3eeca89c2ca6abb5f3e9e497e2.tar.gz lz4-321506974125cb3eeca89c2ca6abb5f3e9e497e2.tar.bz2 |
Merge branch 'dev' of github.com:Cyan4973/lz4 into dev
Diffstat (limited to 'programs/util.h')
-rw-r--r-- | programs/util.h | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/programs/util.h b/programs/util.h index 4aba6a3..6a35481 100644 --- a/programs/util.h +++ b/programs/util.h @@ -45,6 +45,7 @@ extern "C" { # include <utime.h> /* utime */ #endif #include <time.h> /* time */ +#include <limits.h> /* INT_MAX */ #include <errno.h> @@ -391,11 +392,11 @@ UTIL_STATIC void* UTIL_realloc(void* ptr, size_t size) UTIL_STATIC int UTIL_prepareFileList(const char* dirName, char** bufStart, size_t* pos, char** bufEnd) { char* path; - int dirLength, nbFiles = 0; + size_t dirLength, nbFiles = 0; WIN32_FIND_DATAA cFile; HANDLE hFile; - dirLength = (int)strlen(dirName); + dirLength = strlen(dirName); path = (char*) malloc(dirLength + 3); if (!path) return 0; @@ -412,7 +413,7 @@ UTIL_STATIC int UTIL_prepareFileList(const char* dirName, char** bufStart, size_ free(path); do { - int pathLength; + size_t pathLength; int const fnameLength = (int)strlen(cFile.cFileName); path = (char*) malloc(dirLength + fnameLength + 2); if (!path) { FindClose(hFile); return 0; } @@ -445,7 +446,8 @@ UTIL_STATIC int UTIL_prepareFileList(const char* dirName, char** bufStart, size_ } while (FindNextFileA(hFile, &cFile)); FindClose(hFile); - return nbFiles; + assert(nbFiles < INT_MAX); + return (int)nbFiles; } #elif defined(__linux__) || (PLATFORM_POSIX_VERSION >= 200112L) /* opendir, readdir require POSIX.1-2001 */ @@ -553,15 +555,15 @@ UTIL_createFileList(const char** inputNames, unsigned inputNamesNb, char** alloc } } else { char* bufend = buf + bufSize; - nbFiles += UTIL_prepareFileList(inputNames[i], &buf, &pos, &bufend); + nbFiles += (unsigned)UTIL_prepareFileList(inputNames[i], &buf, &pos, &bufend); if (buf == NULL) return NULL; assert(bufend > buf); - bufSize = bufend - buf; + bufSize = (size_t)(bufend - buf); } } if (nbFiles == 0) { free(buf); return NULL; } - fileTable = (const char**)malloc((nbFiles+1) * sizeof(const char*)); + fileTable = (const char**)malloc(((size_t)nbFiles+1) * sizeof(const char*)); if (!fileTable) { free(buf); return NULL; } for (i=0, pos=0; i<nbFiles; i++) { @@ -569,7 +571,11 @@ UTIL_createFileList(const char** inputNames, unsigned inputNamesNb, char** alloc pos += strlen(fileTable[i]) + 1; } - if (pos > bufSize) { free(buf); free((void*)fileTable); return NULL; } /* can this happen ? */ + if (pos > bufSize) { + free(buf); + free((void*)fileTable); + return NULL; + } /* can this happen ? */ *allocatedBuffer = buf; *allocatedNamesNb = nbFiles; |