diff --git a/tools/msi2lmp/README b/tools/msi2lmp/README index 93179b5794..9c9dcdb1a0 100644 --- a/tools/msi2lmp/README +++ b/tools/msi2lmp/README @@ -1,6 +1,12 @@ Axel Kohlmeyer is the current maintainer of the msi2lmp tool. Please send any inquiries about msi2lmp to the lammps-users mailing list. +11 Sep 2014 Axel Kohlmeyer + +Refactored ReadMdfFile.c so it more consistently honors +the MAX_NAME and MAX_STRING string length defines and +potentially handles inputs with long names better. + 27 May 2014 Axel Kohlmeyer Added TopoTools style type hints as comments to all Mass, PairCoeff, diff --git a/tools/msi2lmp/src/ReadMdfFile.c b/tools/msi2lmp/src/ReadMdfFile.c index d3bffc175f..9bc820f37e 100644 --- a/tools/msi2lmp/src/ReadMdfFile.c +++ b/tools/msi2lmp/src/ReadMdfFile.c @@ -112,16 +112,16 @@ void ReadMdfFile(void) in starting and ending atom positions for each residue */ - temp_string = (char *)calloc(16,sizeof(char)); + temp_string = (char *)calloc(MAX_STRING,sizeof(char)); for (n=0; n < no_molecules; n++) { molecule[n].no_residues = 1; - strncpy(temp_string,atoms[molecule[n].start].residue_string,16); + strncpy(temp_string,atoms[molecule[n].start].residue_string,MAX_NAME); for (i=molecule[n].start+1; i < molecule[n].end; i++) { - if (strncmp(temp_string,atoms[i].residue_string,16) != 0) { + if (strncmp(temp_string,atoms[i].residue_string,MAX_NAME) != 0) { molecule[n].no_residues++; - strncpy(temp_string,atoms[i].residue_string,16); + strncpy(temp_string,atoms[i].residue_string,MAX_NAME); } } @@ -136,16 +136,16 @@ void ReadMdfFile(void) for (n=0; n < no_molecules; n++) { j = 0; strncpy(molecule[n].residue[j].name, - atoms[molecule[n].start].residue_string,16); + atoms[molecule[n].start].residue_string,MAX_NAME); molecule[n].residue[j].start = molecule[n].start; for (i=molecule[n].start+1; i < molecule[n].end; i++) { if (strncmp(molecule[n].residue[j].name, - atoms[i].residue_string,16) != 0) { + atoms[i].residue_string,MAX_NAME) != 0) { molecule[n].residue[j].end = i; molecule[n].residue[++j].start = i; - strncpy(molecule[n].residue[j].name,atoms[i].residue_string,16); + strncpy(molecule[n].residue[j].name,atoms[i].residue_string,MAX_NAME); } } molecule[n].residue[j].end = molecule[n].end; @@ -171,7 +171,7 @@ void ReadMdfFile(void) for (i=molecule[n].residue[j].start; i < molecule[n].residue[j].end; i++) { for (l=0; l < atoms[i].no_connect; l++) { - strncpy(temp_string,atoms[i].connections[l],16); + strncpy(temp_string,atoms[i].connections[l],MAX_STRING); temp_residue = strtok(temp_string,":"); temp_atom_name = strtok(NULL,"%"); @@ -334,7 +334,7 @@ void MakeConnectFullForm(int *counter) { int i; /* Counter for character array */ int j; /* loop counter */ - char tempname[MAX_STRING]; /* name of connection */ + char tempname[2*MAX_STRING]; /* name of connection */ char tempcell[10]; /* Values from connectivity record */ char tempsym[5]; /* " " */ char tempbo[6]; /* " " */ @@ -347,6 +347,8 @@ void MakeConnectFullForm(int *counter) { strcat(tempname,":"); strcat(tempname, atoms[*counter].connections[j]); + /* truncate at capacity of target storage */ + tempname[MAX_STRING-1] = '\0'; sscanf(tempname, "%s", atoms[*counter].connections[j]); } else sscanf(atoms[*counter].connections[j], "%s", tempname); @@ -396,8 +398,13 @@ void MakeConnectFullForm(int *counter) { strcat( tempname, tempsym); strcat( tempname, "/"); strcat( tempname, tempbo); - if (strlen(tempname) > 25) printf("tempname overrun %s\n",tempname); - sscanf( tempname, "%s", atoms[*counter].connections[j]); + if (strlen(tempname) >= MAX_STRING) { + printf("tempname overrun %s. truncating to ",tempname); + /* truncate at capacity of target storage */ + tempname[MAX_STRING-1] = '\0'; + puts(tempname); + } + sscanf(tempname, "%s", atoms[*counter].connections[j]); }/*End for loop*/ }/* End function MakeNameLong */ diff --git a/tools/msi2lmp/src/msi2lmp.c b/tools/msi2lmp/src/msi2lmp.c index 20f30e2234..44eec8f6c8 100644 --- a/tools/msi2lmp/src/msi2lmp.c +++ b/tools/msi2lmp/src/msi2lmp.c @@ -2,6 +2,9 @@ * * msi2lmp.exe * +* v3.9.6 AK- Refactoring of MDF file parser with more consistent +* handling of compile time constants MAX_NAME and MAX_STRING +* * v3.9.5 AK- Add TopoTools style force field parameter type hints * * v3.9.4 AK- Make force field style hints optional with a flag diff --git a/tools/msi2lmp/src/msi2lmp.h b/tools/msi2lmp/src/msi2lmp.h index 1db78e0689..009bf74267 100644 --- a/tools/msi2lmp/src/msi2lmp.h +++ b/tools/msi2lmp/src/msi2lmp.h @@ -36,7 +36,7 @@ # include -#define MSI2LMP_VERSION "v3.9.5 / 27 May 2014" +#define MSI2LMP_VERSION "v3.9.6 / 11 Sep 2014" #define PI_180 0.01745329251994329576