hoene / libmysofa

Reader for AES SOFA files to get better HRTFs
Other
131 stars 70 forks source link

Fix offset check in mysofa_seek when used in memory mode. #202

Closed andreasfranck closed 1 year ago

andreasfranck commented 1 year ago

Since f4ba5014d3202f3ecd1715e3cc8265bd9ed5585d, the unit test 'external' fails with the message

libmysofa/src/tests/check_data.c:50 - CU_FAIL_FATAL("Error reading data.")

This is caused by the check in mysofa_seek (reader.c)

if(offset < 0 || offset >= reader->memory_len) {

However, the call mysofa_seek(reader, 0, SEEK_END) (used, e.g., in superblockRead2or3()) invariably results in offset == reader->memory_len, which appears to be correct for the end-of-file position.

Therefore I think the error check should be

if(offset < 0 || offset > reader->memory_len) {.

With that all unit tests are passing locally (tested on Linux and MacOS).