summaryrefslogtreecommitdiffstats
path: root/programs/util.h
diff options
context:
space:
mode:
Diffstat (limited to 'programs/util.h')
-rw-r--r--programs/util.h22
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;