diff options
author | Mark Thompson <sw@jkqxz.net> | 2017-06-19 19:09:34 +0100 |
---|---|---|
committer | Xiang, Haihao <haihao.xiang@intel.com> | 2017-09-27 12:48:16 +0800 |
commit | ef9937d435e6cca985a94a5e2c4effb4c4502601 (patch) | |
tree | 78e1ae5ac251eb8390bde87e50e70daf1ea48ce4 /va/va_fool.c | |
parent | 3da712d668d065476b0fee5fcf5aaf33d63cd2d2 (diff) | |
download | libva-ef9937d435e6cca985a94a5e2c4effb4c4502601.tar.gz |
Detect short reads when filling fool buffers
Mainly to fix the warning (glibc marks read(2) with warn_unused_result).
The function continues anyway when this happens (matching current
behaviour when the file can't be opened at all).
Signed-off-by: Mark Thompson <sw@jkqxz.net>
Diffstat (limited to 'va/va_fool.c')
-rw-r--r-- | va/va_fool.c | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/va/va_fool.c b/va/va_fool.c index 5218404..3307374 100644 --- a/va/va_fool.c +++ b/va/va_fool.c @@ -269,6 +269,7 @@ static int va_FoolFillCodedBufEnc(struct fool_context *fool_ctx) struct stat file_stat = {0}; VACodedBufferSegment *codedbuf; int i, fd = -1; + ssize_t ret; /* try file_name.file_count, if fail, try file_name.file_count-- */ for (i=0; i<=1; i++) { @@ -285,7 +286,9 @@ static int va_FoolFillCodedBufEnc(struct fool_context *fool_ctx) } if (fd != -1) { fool_ctx->segbuf_enc = realloc(fool_ctx->segbuf_enc, file_stat.st_size); - read(fd, fool_ctx->segbuf_enc, file_stat.st_size); + ret = read(fd, fool_ctx->segbuf_enc, file_stat.st_size); + if (ret < file_stat.st_size) + va_errorMessage("Reading file %s failed.\n", file_name); close(fd); } else va_errorMessage("Open file %s failed:%s\n", file_name, strerror(errno)); @@ -306,11 +309,14 @@ static int va_FoolFillCodedBufJPG(struct fool_context *fool_ctx) struct stat file_stat = {0}; VACodedBufferSegment *codedbuf; int fd = -1; + ssize_t ret; if ((fd = open(fool_ctx->fn_jpg, O_RDONLY)) != -1) { fstat(fd, &file_stat); fool_ctx->segbuf_jpg = realloc(fool_ctx->segbuf_jpg, file_stat.st_size); - read(fd, fool_ctx->segbuf_jpg, file_stat.st_size); + ret = read(fd, fool_ctx->segbuf_jpg, file_stat.st_size); + if (ret < file_stat.st_size) + va_errorMessage("Reading file %s failed.\n", fool_ctx->fn_jpg); close(fd); } else va_errorMessage("Open file %s failed:%s\n", fool_ctx->fn_jpg, strerror(errno)); |