Browse Source

Merge commit 'cbfdbba58e1460bd0791911ad84a6c76b5500a0e' into release/2.4

* commit 'cbfdbba58e1460bd0791911ad84a6c76b5500a0e':
  cmdutils: check file access functions return values

Conflicts:
	cmdutils.c

Merged-by: Michael Niedermayer <michaelni@gmx.at>
tags/n2.4.7
Michael Niedermayer 11 years ago
parent
commit
e7b8fa2c00
1 changed files with 23 additions and 9 deletions
  1. +23
    -9
      cmdutils.c

+ 23
- 9
cmdutils.c View File

@@ -1865,19 +1865,31 @@ int cmdutils_read_file(const char *filename, char **bufptr, size_t *size)
strerror(errno)); strerror(errno));
return AVERROR(errno); return AVERROR(errno);
} }
fseek(f, 0, SEEK_END);
*size = ftell(f);
fseek(f, 0, SEEK_SET);
if (*size == (size_t)-1) {
av_log(NULL, AV_LOG_ERROR, "IO error: %s\n", strerror(errno));
fclose(f);
return AVERROR(errno);

ret = fseek(f, 0, SEEK_END);
if (ret == -1) {
ret = AVERROR(errno);
goto out;
}

ret = ftell(f);
if (ret < 0) {
ret = AVERROR(errno);
goto out;
} }
*size = ret;

ret = fseek(f, 0, SEEK_SET);
if (ret == -1) {
ret = AVERROR(errno);
goto out;
}

*bufptr = av_malloc(*size + 1); *bufptr = av_malloc(*size + 1);
if (!*bufptr) { if (!*bufptr) {
av_log(NULL, AV_LOG_ERROR, "Could not allocate file buffer\n"); av_log(NULL, AV_LOG_ERROR, "Could not allocate file buffer\n");
fclose(f);
return AVERROR(ENOMEM);
ret = AVERROR(ENOMEM);
goto out;
} }
ret = fread(*bufptr, 1, *size, f); ret = fread(*bufptr, 1, *size, f);
if (ret < *size) { if (ret < *size) {
@@ -1893,6 +1905,8 @@ int cmdutils_read_file(const char *filename, char **bufptr, size_t *size)
(*bufptr)[(*size)++] = '\0'; (*bufptr)[(*size)++] = '\0';
} }


out:
av_log(NULL, AV_LOG_ERROR, "IO error: %s\n", av_err2str(ret));
fclose(f); fclose(f);
return ret; return ret;
} }


Loading…
Cancel
Save