aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJanne Grunau <janne-libav@jannau.net>2011-10-30 15:34:32 +0100
committerJanne Grunau <janne-libav@jannau.net>2011-10-30 15:52:18 +0100
commitd94c577d3c61e428cfcbcd3dc3a80bd848077eae (patch)
tree803a0a4dd7c926c85ccc0ac512a6168f00a2f6ca
parent7d1b17b83330aefe2f32a66fe84effe46ae51014 (diff)
downloadffmpeg-d94c577d3c61e428cfcbcd3dc3a80bd848077eae.tar.gz
cmdutils: check fread() return value
-rw-r--r--cmdutils.c18
1 files changed, 15 insertions, 3 deletions
diff --git a/cmdutils.c b/cmdutils.c
index ade3f10ce2..c158de36e8 100644
--- a/cmdutils.c
+++ b/cmdutils.c
@@ -787,6 +787,7 @@ int read_yesno(void)
int read_file(const char *filename, char **bufptr, size_t *size)
{
+ int ret;
FILE *f = fopen(filename, "rb");
if (!f) {
@@ -802,11 +803,22 @@ int read_file(const char *filename, char **bufptr, size_t *size)
fclose(f);
return AVERROR(ENOMEM);
}
- fread(*bufptr, 1, *size, f);
- (*bufptr)[*size++] = '\0';
+ ret = fread(*bufptr, 1, *size, f);
+ if (ret < *size) {
+ av_free(*bufptr);
+ if (ferror(f)) {
+ av_log(NULL, AV_LOG_ERROR, "Error while reading file '%s': %s\n",
+ filename, strerror(errno));
+ ret = AVERROR(errno);
+ } else
+ ret = AVERROR_EOF;
+ } else {
+ ret = 0;
+ (*bufptr)[*size++] = '\0';
+ }
fclose(f);
- return 0;
+ return ret;
}
void init_pts_correction(PtsCorrectionContext *ctx)