# HG changeset patch # User zas_ # Date 1227731990 0 # Node ID 475986f8f29816e2f079ce1254fd9e3c1e1b22db # Parent f5bea35b4316e2e46131591787e114a8551db0b9 Handle return values better to silent some warnings. diff -r f5bea35b4316 -r 475986f8f298 src/thumb.c --- a/src/thumb.c Wed Nov 26 20:38:47 2008 +0000 +++ b/src/thumb.c Wed Nov 26 20:39:50 2008 +0000 @@ -573,33 +573,32 @@ { FILE *file; gchar buffer[XV_BUFFER]; - guchar *data; - gint width, height, depth; + guchar *data = NULL; file = fopen(filename, "rt"); if (!file) return NULL; - fgets(buffer, XV_BUFFER, file); - if (strncmp(buffer, "P7 332", 6) != 0) + if (fgets(buffer, XV_BUFFER, file) != NULL + && strncmp(buffer, "P7 332", 6) == 0) { - fclose(file); - return NULL; + gint width, height, depth; + + while (fgets(buffer, XV_BUFFER, file) && buffer[0] == '#') /* do_nothing() */; + + if (sscanf(buffer, "%d %d %d", &width, &height, &depth) == 3) + { + gsize size = width * height; + + data = g_new(guchar, size); + if (data && fread(data, 1, size, file) == size) + { + *widthp = width; + *heightp = height; + } + } } - while (fgets(buffer, XV_BUFFER, file) && buffer[0] == '#') /* do_nothing() */; - - if (sscanf(buffer, "%d %d %d", &width, &height, &depth) != 3) - { - fclose(file); - return NULL; - } - - data = g_new(guchar, width * height); - fread(data, 1, width * height, file); - fclose(file); - *widthp = width; - *heightp = height; return data; } #undef XV_BUFFER