diff --git a/src/atom.cpp b/src/atom.cpp index e1b459750b..103fd5bc57 100644 --- a/src/atom.cpp +++ b/src/atom.cpp @@ -805,8 +805,11 @@ void Atom::data_atoms(int n, char *buf) next = strchr(buf,'\n'); values[0] = strtok(buf," \t\n\r\f"); - for (m = 1; m < nwords; m++) + if (values[0] == NULL) error->all("Incorrect atom format in data file"); + for (m = 1; m < nwords; m++) { values[m] = strtok(NULL," \t\n\r\f"); + if (values[m] == NULL) error->all("Incorrect atom format in data file"); + } if (imageflag) imagedata = ((atoi(values[iptr+2]) + 512 & 1023) << 20) | diff --git a/src/read_data.cpp b/src/read_data.cpp index c3e513b458..3b7127dccf 100644 --- a/src/read_data.cpp +++ b/src/read_data.cpp @@ -461,6 +461,7 @@ void ReadData::atoms() } buffer[m++] = '\n'; } + buffer[m] = '\0'; MPI_Bcast(&m,1,MPI_INT,0,world); MPI_Bcast(buffer,m,MPI_CHAR,0,world); @@ -552,6 +553,7 @@ void ReadData::velocities() } buffer[m++] = '\n'; } + buffer[m] = '\0'; MPI_Bcast(&m,1,MPI_INT,0,world); MPI_Bcast(buffer,m,MPI_CHAR,0,world); @@ -603,6 +605,7 @@ void ReadData::ellipsoids() } buffer[m++] = '\n'; } + buffer[m] = '\0'; MPI_Bcast(&m,1,MPI_INT,0,world); MPI_Bcast(buffer,m,MPI_CHAR,0,world); @@ -642,6 +645,7 @@ void ReadData::bonds() } buffer[m++] = '\n'; } + buffer[m] = '\0'; MPI_Bcast(&m,1,MPI_INT,0,world); MPI_Bcast(buffer,m,MPI_CHAR,0,world); @@ -687,6 +691,7 @@ void ReadData::angles() } buffer[m++] = '\n'; } + buffer[m] = '\0'; MPI_Bcast(&m,1,MPI_INT,0,world); MPI_Bcast(buffer,m,MPI_CHAR,0,world); @@ -732,6 +737,7 @@ void ReadData::dihedrals() } buffer[m++] = '\n'; } + buffer[m] = '\0'; MPI_Bcast(&m,1,MPI_INT,0,world); MPI_Bcast(buffer,m,MPI_CHAR,0,world); @@ -778,6 +784,7 @@ void ReadData::impropers() } buffer[m++] = '\n'; } + buffer[m] = '\0'; MPI_Bcast(&m,1,MPI_INT,0,world); MPI_Bcast(buffer,m,MPI_CHAR,0,world);