Skip to content
Snippets Groups Projects
Commit d94c577d authored by Janne Grunau's avatar Janne Grunau
Browse files

cmdutils: check fread() return value

parent 7d1b17b8
No related branches found
No related tags found
No related merge requests found
...@@ -787,6 +787,7 @@ int read_yesno(void) ...@@ -787,6 +787,7 @@ int read_yesno(void)
int read_file(const char *filename, char **bufptr, size_t *size) int read_file(const char *filename, char **bufptr, size_t *size)
{ {
int ret;
FILE *f = fopen(filename, "rb"); FILE *f = fopen(filename, "rb");
if (!f) { if (!f) {
...@@ -802,11 +803,22 @@ int read_file(const char *filename, char **bufptr, size_t *size) ...@@ -802,11 +803,22 @@ int read_file(const char *filename, char **bufptr, size_t *size)
fclose(f); fclose(f);
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
} }
fread(*bufptr, 1, *size, f); ret = fread(*bufptr, 1, *size, f);
(*bufptr)[*size++] = '\0'; 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); fclose(f);
return 0; return ret;
} }
void init_pts_correction(PtsCorrectionContext *ctx) void init_pts_correction(PtsCorrectionContext *ctx)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment