From 37d8ad2e49a3e310090b4df3f3b206468a4f85b3 Mon Sep 17 00:00:00 2001 From: Pierre Kestener Date: Thu, 25 Apr 2024 11:02:22 +0200 Subject: [PATCH] Increase size limits. See https://github.com/rogersce/cnpy/issues/98 --- src/cnpy.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/cnpy.cpp b/src/cnpy.cpp index f70cc03..7abfe96 100644 --- a/src/cnpy.cpp +++ b/src/cnpy.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include char @@ -116,7 +117,10 @@ cnpy::parse_npy_header(unsigned char * buffer, std::string str_shape = header.substr(loc1 + 1, loc2 - loc1 - 1); while (std::regex_search(str_shape, sm, num_regex)) { - shape.push_back(std::stoi(sm[0].str())); + std::stringstream stream(sm[0].str()); + size_t size; + stream >> size; + shape.push_back(size); str_shape = sm.suffix().str(); } @@ -170,7 +174,11 @@ cnpy::parse_npy_header(FILE * fp, std::string str_shape = header.substr(loc1 + 1, loc2 - loc1 - 1); while (std::regex_search(str_shape, sm, num_regex)) { - shape.push_back(std::stoi(sm[0].str())); + std::stringstream stream(sm[0].str()); + size_t size; + stream >> size; + + shape.push_back(size); str_shape = sm.suffix().str(); }