aboutsummaryrefslogtreecommitdiffstats
path: root/cmdutils.c
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2011-10-31 02:26:37 +0100
committerMichael Niedermayer <michaelni@gmx.at>2011-10-31 02:26:47 +0100
commit0489af478e5f490aee2d96daa29043b590c8d280 (patch)
tree4b87c989fd78132150f8bed362d19d081ac50e47 /cmdutils.c
parente484b64ce37e7bc7556c6113ce6f10671e20f61f (diff)
parent45235d69c271966409cdd3eaa022258c22e04fdb (diff)
downloadffmpeg-0489af478e5f490aee2d96daa29043b590c8d280.tar.gz
Merge remote-tracking branch 'qatar/master'
* qatar/master: libdirac/libschroedinger: Drop unnecessary symbol prefixes. cmdutils: check fread() return value Merged-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'cmdutils.c')
-rw-r--r--cmdutils.c18
1 files changed, 15 insertions, 3 deletions
diff --git a/cmdutils.c b/cmdutils.c
index 00c5d71144..30104fd6b9 100644
--- a/cmdutils.c
+++ b/cmdutils.c
@@ -809,6 +809,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) {
@@ -824,11 +825,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;
}
FILE *get_preset_file(char *filename, size_t filename_size,