diff options
author | Sybren A. Stüvel <sybren@blender.org> | 2021-01-11 19:29:21 +0300 |
---|---|---|
committer | Sybren A. Stüvel <sybren@blender.org> | 2021-01-11 19:29:21 +0300 |
commit | b271475a9e0ba69a5b48da92c4895e65325dda86 (patch) | |
tree | 35e24e8997b3732b3a23846f408c990b8e4c2363 /source/blender/imbuf | |
parent | bf90fcda4760f52ea7cebcceb7dc0d0e1a7de93a (diff) |
ImBuf: Add error handling to IMB_indexer_open
Handle return value of `fread()` by printing an error and closing the
file when it cannot be read from. Not only is error handing a good idea,
it also prevents GCC from warning that the return value of `fread()`
should not be ignored:
```
.../blender/source/blender/imbuf/intern/indexer.c: In function ‘IMB_indexer_open’:
.../blender/source/blender/imbuf/intern/indexer.c:201:5: warning: ignoring return value of ‘fread’, declared with attribute warn_unused_result [-Wunused-result]
201 | fread(&idx->entries[i].frameno, sizeof(int), 1, fp);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.../blender/source/blender/imbuf/intern/indexer.c:202:5: warning: ignoring return value of ‘fread’, declared with attribute warn_unused_result [-Wunused-result]
202 | fread(&idx->entries[i].seek_pos, sizeof(unsigned long long), 1, fp);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.../blender/source/blender/imbuf/intern/indexer.c:203:5: warning: ignoring return value of ‘fread’, declared with attribute warn_unused_result [-Wunused-result]
203 | fread(&idx->entries[i].seek_pos_dts, sizeof(unsigned long long), 1, fp);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.../blender/source/blender/imbuf/intern/indexer.c:204:5: warning: ignoring return value of ‘fread’, declared with attribute warn_unused_result [-Wunused-result]
204 | fread(&idx->entries[i].pts, sizeof(unsigned long long), 1, fp);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
```
Differential Revision: https://developer.blender.org/D9916
Reviewed by: campbellbarton
Diffstat (limited to 'source/blender/imbuf')
-rw-r--r-- | source/blender/imbuf/intern/indexer.c | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/source/blender/imbuf/intern/indexer.c b/source/blender/imbuf/intern/indexer.c index b5b8cd4a580..09f37d733de 100644 --- a/source/blender/imbuf/intern/indexer.c +++ b/source/blender/imbuf/intern/indexer.c @@ -198,10 +198,19 @@ struct anim_index *IMB_indexer_open(const char *name) "anim_index_entries"); for (i = 0; i < idx->num_entries; i++) { - fread(&idx->entries[i].frameno, sizeof(int), 1, fp); - fread(&idx->entries[i].seek_pos, sizeof(unsigned long long), 1, fp); - fread(&idx->entries[i].seek_pos_dts, sizeof(unsigned long long), 1, fp); - fread(&idx->entries[i].pts, sizeof(unsigned long long), 1, fp); + size_t items_read = 0; + items_read += fread(&idx->entries[i].frameno, sizeof(int), 1, fp); + items_read += fread(&idx->entries[i].seek_pos, sizeof(unsigned long long), 1, fp); + items_read += fread(&idx->entries[i].seek_pos_dts, sizeof(unsigned long long), 1, fp); + items_read += fread(&idx->entries[i].pts, sizeof(unsigned long long), 1, fp); + + if (items_read < 4) { + perror("error reading animation index file"); + MEM_freeN(idx->entries); + MEM_freeN(idx); + fclose(fp); + return NULL; + } } if (((ENDIAN_ORDER == B_ENDIAN) != (header[8] == 'V'))) { |