From 423772b1fae1c985c6a8d3f5a4a6db69e3b221f2 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 11 Mar 2021 06:46:40 -0500 Subject: [PATCH] avoid strtok() when processing the "partition" command --- src/input.cpp | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/input.cpp b/src/input.cpp index df5cf0efbe..eeb211a6d1 100644 --- a/src/input.cpp +++ b/src/input.cpp @@ -1076,22 +1076,20 @@ void Input::partition() int ilo,ihi; utils::bounds(FLERR,arg[1],1,universe->nworlds,ilo,ihi,error); - // copy original line to copy, since will use strtok() on it - // ptr = start of 4th word + // new command starts at the 3rd argument, + // which must not be another partition command - strcpy(copy,line); - char *ptr = strtok(copy," \t\n\r\f"); - ptr = strtok(nullptr," \t\n\r\f"); - ptr = strtok(nullptr," \t\n\r\f"); - ptr += strlen(ptr) + 1; - ptr += strspn(ptr," \t\n\r\f"); + if (strcmp(arg[2],"partition") == 0) + error->all(FLERR,"Illegal partition command"); + + char *cmd = strstr(line,arg[2]); // execute the remaining command line on requested partitions if (yesflag) { - if (universe->iworld+1 >= ilo && universe->iworld+1 <= ihi) one(ptr); + if (universe->iworld+1 >= ilo && universe->iworld+1 <= ihi) one(cmd); } else { - if (universe->iworld+1 < ilo || universe->iworld+1 > ihi) one(ptr); + if (universe->iworld+1 < ilo || universe->iworld+1 > ihi) one(cmd); } }