Mercurial > mplayer.hg
changeset 35359:4bdb1cc07953
Check return value after reading file.
Reading may fail.
Additionally, adjust error codes.
author | ib |
---|---|
date | Fri, 23 Nov 2012 10:24:10 +0000 |
parents | 37b9f0e82a31 |
children | a3e8af09792d |
files | gui/util/bitmap.c |
diffstat | 1 files changed, 9 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/gui/util/bitmap.c Fri Nov 23 10:15:43 2012 +0000 +++ b/gui/util/bitmap.c Fri Nov 23 10:24:10 2012 +0000 @@ -42,12 +42,12 @@ * @param img pointer suitable to store the image data * * @return 0 (ok), 1 (decoding error), 2 (open error), 3 (file too big), - * 4 (out of memory), 5 (avcodec alloc error) + * 4 (out of memory), 5 (read error), 6 (avcodec alloc error) */ static int pngRead(const char *fname, guiImage *img) { FILE *file; - size_t len; + size_t len, l; void *data; int decode_ok, bpl; AVCodecContext *avctx; @@ -75,9 +75,14 @@ } fseek(file, 0, SEEK_SET); - fread(data, len, 1, file); + l = fread(data, len, 1, file); fclose(file); + if (l != 1) { + av_free(data); + return 5; + } + avctx = avcodec_alloc_context3(NULL); frame = avcodec_alloc_frame(); @@ -85,7 +90,7 @@ av_free(frame); av_free(avctx); av_free(data); - return 5; + return 6; } avcodec_register_all();