Fix NPY header length error due to signed->unsigned conversion by Kwonunn · Pull Request #2889 · xtensor-stack/xtensor
Checklist
- The title and commit message(s) are descriptive.
- Small commits made to fix your PR have been squashed to avoid history pollution.
- Tests have been added for new features or bug fixes.
-
API of new functions and classes are documented.
Description
This PR fixes an error pertaining to reading the length of the header of an npy file. The header is read as two chars and then combined into a uint16_t. Previously due to char being a signed value, any value with the MSB set would get converted as if it were a negative number and thus misinterpreted.
For example, the bytes F6 00 which means a header of 246 bytes would be interpreted as a header of 65526 bytes.
I think the code could be shortened a little, but I think when messing with bits like this it's best to be explicit. Also, the compiler will likely optimize it anyway.