Fixed sign-compare warnings

This commit is contained in:
Armin Novak 2019-02-07 14:37:23 +01:00
parent 4c2028e285
commit 29741ca849
4 changed files with 24 additions and 17 deletions

View File

@ -364,7 +364,8 @@ unsigned lodepng_load_file(unsigned char** out, size_t* outsize, const char* fil
if(size && (*out)) (*outsize) = fread(*out, 1, (size_t)size, file);
fclose(file);
if (*outsize != size) return 91;
if (size < 0) return 91;
if (*outsize != (size_t)size) return 91;
if(!(*out) && size) return 83; /*the above malloc failed*/
return 0;
}

View File

@ -5,11 +5,12 @@
int TestArrayList(int argc, char* argv[])
{
int index;
size_t index;
int count;
int rc;
size_t val;
wArrayList* arrayList;
const int elemsToInsert = 10;
const size_t elemsToInsert = 10;
arrayList = ArrayList_New(TRUE);
if (!arrayList)
@ -17,7 +18,7 @@ int TestArrayList(int argc, char* argv[])
for (index = 0; index < elemsToInsert; index++)
{
if (ArrayList_Add(arrayList, (void*) (size_t) index) < 0)
if (ArrayList_Add(arrayList, (void*) index) < 0)
return -1;
}
@ -27,7 +28,7 @@ int TestArrayList(int argc, char* argv[])
index = ArrayList_IndexOf(arrayList, (void*) (size_t) 6, -1, -1);
printf("ArrayList index: %d\n", index);
printf("ArrayList index: %"PRIdz"\n", index);
if (index != 6)
return -1;
@ -35,22 +36,23 @@ int TestArrayList(int argc, char* argv[])
ArrayList_Insert(arrayList, 5, (void*) (size_t) 100);
index = ArrayList_IndexOf(arrayList, (void*) (size_t) 6, -1, -1);
printf("ArrayList index: %d\n", index);
printf("ArrayList index: %"PRIdz"\n", index);
if (index != 7)
return -1;
ArrayList_Remove(arrayList, (void*) (size_t) 100);
index = ArrayList_IndexOf(arrayList, (void*) (size_t) 6, -1, -1);
printf("ArrayList index: %d\n", index);
rc = ArrayList_IndexOf(arrayList, (void*) (size_t) 6, -1, -1);
printf("ArrayList index: %d\n", rc);
if (index != 6)
if (rc != 6)
return -1;
for (index = 0; index < elemsToInsert; index++) {
val = (size_t)ArrayList_GetItem(arrayList, 0);
ArrayList_RemoveAt(arrayList, 0);
if (!ArrayList_RemoveAt(arrayList, 0))
return -1;
if (val != index)
{
printf("ArrayList: shifted %"PRIdz" entries, expected value %"PRIdz", got %"PRIdz"\n", index, index, val);
@ -58,9 +60,9 @@ int TestArrayList(int argc, char* argv[])
}
}
index = ArrayList_IndexOf(arrayList, (void*) (size_t) elemsToInsert, -1, -1);
printf("ArrayList index: %d\n", index);
if (index != -1)
rc = ArrayList_IndexOf(arrayList, (void*) (size_t) elemsToInsert, -1, -1);
printf("ArrayList index: %d\n", rc);
if (rc != -1)
return -1;
count = ArrayList_Count(arrayList);

View File

@ -9,7 +9,7 @@ int TestBufferPool(int argc, char* argv[])
int BufferSize;
wBufferPool* pool;
BYTE* Buffers[10];
DWORD DefaultSize = 1234;
int DefaultSize = 1234;
pool = BufferPool_New(TRUE, -1, 16);
if (!pool)

View File

@ -29,14 +29,18 @@ static void* read_image(const char* src, size_t* size)
}
src_size = _ftelli64(fsrc);
if (src_size < 0)
{
fprintf(stderr, "Invalid file position %"PRId64"\n", src_size);
goto cleanup;
}
if (_fseeki64(fsrc, 0, SEEK_SET))
{
fprintf(stderr, "Failed to seek to SEEK_SET\n");
goto cleanup;
}
a = malloc(src_size);
a = malloc((size_t)src_size);
if (!a)
{
@ -44,7 +48,7 @@ static void* read_image(const char* src, size_t* size)
goto cleanup;
}
if (fread(a, sizeof(char), src_size, fsrc) != src_size)
if (fread(a, sizeof(char), (size_t)src_size, fsrc) != (size_t)src_size)
{
fprintf(stderr, "Failed read %"PRId64" bytes\n", src_size);
goto cleanup;