Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions cnpy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,13 @@ void cnpy::parse_npy_header(unsigned char* buffer,size_t& word_size, std::vector
//std::string magic_string(buffer,6);
uint8_t major_version = *reinterpret_cast<uint8_t*>(buffer+6);
uint8_t minor_version = *reinterpret_cast<uint8_t*>(buffer+7);
uint16_t header_len = *reinterpret_cast<uint16_t*>(buffer+8);
std::string header(reinterpret_cast<char*>(buffer+9),header_len);
bool extended_header = (major_version > 1);
uint32_t header_len;
if (extended_header)
header_len = *reinterpret_cast<uint32_t*>(buffer+8);
else
header_len = *reinterpret_cast<uint16_t*>(buffer+8);
std::string header(reinterpret_cast<char*>(buffer+(extended_header ? 11 : 9)),header_len);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since header_len is uint16_t, I think it should be?

Suggested change
std::string header(reinterpret_cast<char*>(buffer+(extended_header ? 11 : 9)),header_len);
std::string header(reinterpret_cast<char*>(buffer+(extended_header ? 12 : 10)),header_len);

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you're right. It's been working because the only use of header has been based on relative locations discovered using find and similar, but we could improve performance (ever so slightly) by using the correct offset.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed. Thanks for pointing this out.


size_t loc1, loc2;

Expand Down