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
This commit is contained in:
@@ -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'))) {
|
||||
|
||||
Reference in New Issue
Block a user