diff options
author | Campbell Barton <ideasman42@gmail.com> | 2021-01-12 06:38:54 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2021-01-12 15:31:34 +0300 |
commit | e0a4b392f3888b8d792e3ab1ad7e311edd2f4c56 (patch) | |
tree | 04ecba729e03e39f8309ae8fe47bef0d7f038948 /source/blender/imbuf | |
parent | 28b17ef0e6a82361f7061b9e074609dde9a76254 (diff) |
Cleanup: use exact check for fread, move out of the loop
Without this, additional items could be added in the future
which wouldn't be included in the check.
Move the check out of the loop since this is such an unlikely
situation that checking every iteration isn't needed.
Also remove redundant casts.
Diffstat (limited to 'source/blender/imbuf')
-rw-r--r-- | source/blender/imbuf/intern/indexer.c | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/source/blender/imbuf/intern/indexer.c b/source/blender/imbuf/intern/indexer.c index 8233483706c..20e1febedd7 100644 --- a/source/blender/imbuf/intern/indexer.c +++ b/source/blender/imbuf/intern/indexer.c @@ -194,28 +194,28 @@ struct anim_index *IMB_indexer_open(const char *name) idx->entries = MEM_callocN(sizeof(struct anim_index_entry) * idx->num_entries, "anim_index_entries"); + size_t items_read = 0; for (i = 0; i < idx->num_entries; i++) { - 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(uint64_t), 1, fp); items_read += fread(&idx->entries[i].seek_pos_dts, sizeof(uint64_t), 1, fp); items_read += fread(&idx->entries[i].pts, sizeof(uint64_t), 1, fp); + } - if (items_read < 4) { - perror("error reading animation index file"); - MEM_freeN(idx->entries); - MEM_freeN(idx); - fclose(fp); - return NULL; - } + if (UNLIKELY(items_read != idx->num_entries * 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'))) { for (i = 0; i < idx->num_entries; i++) { BLI_endian_switch_int32(&idx->entries[i].frameno); - BLI_endian_switch_int64((int64_t *)&idx->entries[i].seek_pos); - BLI_endian_switch_int64((int64_t *)&idx->entries[i].seek_pos_dts); - BLI_endian_switch_int64((int64_t *)&idx->entries[i].pts); + BLI_endian_switch_uint64(&idx->entries[i].seek_pos); + BLI_endian_switch_uint64(&idx->entries[i].seek_pos_dts); + BLI_endian_switch_uint64(&idx->entries[i].pts); } } |