diff --git a/src/reader_native.cpp b/src/reader_native.cpp index 7be546719f..1ee4712989 100644 --- a/src/reader_native.cpp +++ b/src/reader_native.cpp @@ -63,10 +63,10 @@ int ReaderNative::read_time(bigint &ntimestep) magic_string = ""; unit_style = ""; - fread(&ntimestep, sizeof(bigint), 1, fp); + auto ret = fread(&ntimestep, sizeof(bigint), 1, fp); // detect end-of-file - if (feof(fp)) return 1; + if (ret != 1 || feof(fp)) return 1; // detect newer format if (ntimestep < 0) { @@ -485,12 +485,8 @@ void ReaderNative::read_atoms(int n, int nfield, double **fields) } } } else { - int i,m; - char *eof; - - for (i = 0; i < n; i++) { - eof = fgets(line,MAXLINE,fp); - if (eof == nullptr) error->one(FLERR,"Unexpected end of dump file"); + for (int i = 0; i < n; i++) { + utils::sfgets(FLERR, line, MAXLINE, fp, nullptr, error); // tokenize the line std::vector words = Tokenizer(line).as_vector(); @@ -499,7 +495,7 @@ void ReaderNative::read_atoms(int n, int nfield, double **fields) // convert selected fields to floats - for (m = 0; m < nfield; m++) + for (int m = 0; m < nfield; m++) fields[i][m] = atof(words[fieldindex[m]].c_str()); } } @@ -527,18 +523,14 @@ int ReaderNative::find_label(const std::string &label, const std::mapone(FLERR,"Unexpected end of dump file"); + for (int i = 0; i < n; i++) { + utils::sfgets(FLERR, line, MAXLINE, fp, nullptr, error); + } } void ReaderNative::read_buf(void * ptr, size_t size, size_t count) { - fread(ptr, size, count, fp); - - // detect end-of-file - if (feof(fp)) error->one(FLERR,"Unexpected end of dump file"); + utils::sfread(FLERR, ptr, size, count, fp, nullptr, error); } std::string ReaderNative::read_binary_str(size_t size) diff --git a/src/reader_native.h b/src/reader_native.h index c07dbbac08..f888509dfb 100644 --- a/src/reader_native.h +++ b/src/reader_native.h @@ -52,7 +52,7 @@ class ReaderNative : public Reader { int nwords; // # of per-atom columns in dump file int size_one; // number of double for one atom - int maxbuf; // maximum buffer size + size_t maxbuf; // maximum buffer size int nchunk; // number of chunks in the binary file int ichunk; // index of current reading chunk int natom_chunk; // number of atoms in the current chunks