From e6536edb128bd0575bf07514d486eb67b5dfb04b Mon Sep 17 00:00:00 2001 From: carl Date: Tue, 29 May 2018 21:24:21 -0500 Subject: [PATCH] fix some type mismatch issues --- cnpy.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/cnpy.cpp b/cnpy.cpp index 5ca4a7d..b6cc275 100644 --- a/cnpy.cpp +++ b/cnpy.cpp @@ -65,7 +65,7 @@ void cnpy::parse_npy_header(unsigned char* buffer,size_t& word_size, std::vector uint16_t header_len = *reinterpret_cast(buffer+8); std::string header(reinterpret_cast(buffer+9),header_len); - int loc1, loc2; + size_t loc1, loc2; //fortran order loc1 = header.find("fortran_order")+16; @@ -108,11 +108,11 @@ void cnpy::parse_npy_header(FILE* fp, size_t& word_size, std::vector& sh std::string header = fgets(buffer,256,fp); assert(header[header.size()-1] == '\n'); - int loc1, loc2; + size_t loc1, loc2; //fortran order loc1 = header.find("fortran_order"); - if (loc1 < 0) + if (loc1 == std::string::npos) throw std::runtime_error("parse_npy_header: failed to find header keyword: 'fortran_order'"); loc1 += 16; fortran_order = (header.substr(loc1,4) == "True" ? true : false); @@ -120,7 +120,7 @@ void cnpy::parse_npy_header(FILE* fp, size_t& word_size, std::vector& sh //shape loc1 = header.find("("); loc2 = header.find(")"); - if (loc1 < 0 || loc2 < 0) + if (loc1 == std::string::npos || loc2 == std::string::npos) throw std::runtime_error("parse_npy_header: failed to find header keyword: '(' or ')'"); std::string str_shape = header.substr(loc1+1,loc2-loc1-1); @@ -138,7 +138,7 @@ void cnpy::parse_npy_header(FILE* fp, size_t& word_size, std::vector& sh //byte order code | stands for not applicable. //not sure when this applies except for byte array loc1 = header.find("descr"); - if (loc1 < 0) + if (loc1 == std::string::npos) throw std::runtime_error("parse_npy_header: failed to find header keyword: 'descr'"); loc1 += 9; bool littleEndian = (header[loc1] == '<' || header[loc1] == '|' ? true : false); @@ -313,7 +313,7 @@ cnpy::NpyArray cnpy::npz_load(std::string fname, std::string varname) { } else { //skip past the data - size_t size = *(uint32_t*) &local_header[22]; + uint32_t size = *(uint32_t*) &local_header[22]; fseek(fp,size,SEEK_CUR); } }