cnpy.h::npy_save: fix bug when nels = 0 and data = NULL #87
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When nels = 0, no bytes from
const T* data
are written to the npyfile (line 219: fwrite(data,sizeof(T),nels,fp)).
Therefore, the crc of the to-be-written data only needs to be
computed for the numpy header, as done on line 171.
It might be thought that
crc32(initial_crc, data_ptr, data_size)
would always return
initial_crc
ifdata_size = 0
. This is truefor every value of data_ptr except NULL. In this case crc32
returns 0, independent of initial_crc.
The result of calling npz_save with a shape of total size 0
(i.e., the product of all elements in the shape) should not depend
on whether
data
is a null pointer or not.Fix this bug by only updating the crc when nels != 0, independent
of the value of
data
.