Mercurial > geeqie
changeset 1181:475986f8f298
Handle return values better to silent some warnings.
author | zas_ |
---|---|
date | Wed, 26 Nov 2008 20:39:50 +0000 |
parents | f5bea35b4316 |
children | 6ae6d77a1f15 |
files | src/thumb.c |
diffstat | 1 files changed, 18 insertions(+), 19 deletions(-) [+] |
line wrap: on
line diff
--- 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