Skip to content

Commit

Permalink
fix some type mismatch issues
Browse files Browse the repository at this point in the history
  • Loading branch information
carl committed May 30, 2018
1 parent 5cc18b0 commit e6536ed
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions cnpy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ void cnpy::parse_npy_header(unsigned char* buffer,size_t& word_size, std::vector
uint16_t header_len = *reinterpret_cast<uint16_t*>(buffer+8);
std::string header(reinterpret_cast<char*>(buffer+9),header_len);

int loc1, loc2;
size_t loc1, loc2;

//fortran order
loc1 = header.find("fortran_order")+16;
Expand Down Expand Up @@ -108,19 +108,19 @@ void cnpy::parse_npy_header(FILE* fp, size_t& word_size, std::vector<size_t>& 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);

//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);
Expand All @@ -138,7 +138,7 @@ void cnpy::parse_npy_header(FILE* fp, size_t& word_size, std::vector<size_t>& 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);
Expand Down Expand Up @@ -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);
}
}
Expand Down

0 comments on commit e6536ed

Please sign in to comment.