diff --git a/src/balance.cpp b/src/balance.cpp index c8d21f1ac6..92321bcf84 100644 --- a/src/balance.cpp +++ b/src/balance.cpp @@ -196,8 +196,8 @@ void Balance::command(int narg, char **arg) if (style != -1) error->all(FLERR,"Illegal balance command"); if (iarg+4 > narg) error->all(FLERR,"Illegal balance command"); style = SHIFT; - if (strlen(arg[iarg+1]) > 3) error->all(FLERR,"Illegal balance command"); - strcpy(bstr,arg[iarg+1]); + if (strlen(arg[iarg+1]) > BSTR_SIZE) error->all(FLERR,"Illegal balance command"); + strncpy(bstr,arg[iarg+1],BSTR_SIZE); nitermax = utils::inumeric(FLERR,arg[iarg+2],false,lmp); if (nitermax <= 0) error->all(FLERR,"Illegal balance command"); stopthresh = utils::numeric(FLERR,arg[iarg+3],false,lmp); diff --git a/src/balance.h b/src/balance.h index e427c8bd9b..2e3f003fbd 100644 --- a/src/balance.h +++ b/src/balance.h @@ -56,7 +56,8 @@ class Balance : public Command { int nitermax; // params for shift LB double stopthresh; - char bstr[4]; + static constexpr int BSTR_SIZE = 3; + char bstr[BSTR_SIZE+1]; int shift_allocate; // 1 if SHIFT vectors have been allocated int ndim; // length of balance string bstr