rogersce / cnpy

library to read/write .npy and .npz files in C/C++
MIT License
1.34k stars 301 forks source link

Make initial shape accumulate value type explicit #83

Open tvincent056 opened 2 years ago

tvincent056 commented 2 years ago

On many compilers (tested on gcc 9.2) the std::accumulate function will use the type of the initial value as the accumulated value type. The previous version of the code passed a literal '1' which defaults to an 'int' type. This makes the code vulnerable to type overflows for arrays with many elements. Explicitly casting to size_t should fix this.

skaiware commented 2 years ago

@rogersce are you still reviewing PRs ?