Fixing ftell() error handling issue introduced by warning merge from PR 408

This commit is contained in:
Richard Geldreich
2025-11-08 11:28:34 -05:00
parent 703d05cc7a
commit cbb8ebefa4

View File

@@ -631,14 +631,30 @@ void *qoi_read(const char *filename, qoi_desc *desc, int channels) {
#endif
size_t size, bytes_read;
void *pixels, *data;
long sz;
if (!f) {
return NULL;
}
fseek(f, 0, SEEK_END);
size = ftell(f);
if (size <= 0 || fseek(f, 0, SEEK_SET) != 0) {
sz = ftell(f);
if (sz <= 0)
{
fclose(f);
return NULL;
}
size = (size_t)sz;
if (size != sz)
{
fclose(f);
return NULL;
}
if (fseek(f, 0, SEEK_SET) != 0) {
fclose(f);
return NULL;
}