diff --git a/src/domain.cpp b/src/domain.cpp index 1becba5e0b..c6dee63221 100644 --- a/src/domain.cpp +++ b/src/domain.cpp @@ -1826,10 +1826,10 @@ void Domain::delete_region(int narg, char **arg) return -1 if no such region ------------------------------------------------------------------------- */ -int Domain::find_region(char *name) +int Domain::find_region(const std::string &name) { for (int iregion = 0; iregion < nregion; iregion++) - if (strcmp(name,regions[iregion]->id) == 0) return iregion; + if (name == regions[iregion]->id) return iregion; return -1; } diff --git a/src/domain.h b/src/domain.h index c3ea9e2bea..99349edb5d 100644 --- a/src/domain.h +++ b/src/domain.h @@ -130,7 +130,7 @@ class Domain : protected Pointers { void set_lattice(int, char **); void add_region(int, char **); void delete_region(int, char **); - int find_region(char *); + int find_region(const std::string &); void set_boundary(int, char **, int); void set_box(int, char **); void print_box(const std::string &); diff --git a/src/group.cpp b/src/group.cpp index e523fd9cf2..00677cca5a 100644 --- a/src/group.cpp +++ b/src/group.cpp @@ -66,10 +66,7 @@ Group::Group(LAMMPS *lmp) : Pointers(lmp) // create "all" group - char *str = (char *) "all"; - int n = strlen(str) + 1; - names[0] = new char[n]; - strcpy(names[0],str); + names[0] = utils::strdup("all"); ngroup = 1; } @@ -157,9 +154,7 @@ void Group::assign(int narg, char **arg) if (igroup == -1) { if (ngroup == MAX_GROUP) error->all(FLERR,"Too many groups"); igroup = find_unused(); - int n = strlen(arg[0]) + 1; - names[igroup] = new char[n]; - strcpy(names[igroup],arg[0]); + names[igroup] = utils::strdup(arg[0]); ngroup++; } @@ -563,9 +558,7 @@ void Group::create(char *name, int *flag) if (igroup == -1) { if (ngroup == MAX_GROUP) error->all(FLERR,"Too many groups"); igroup = find_unused(); - int n = strlen(name) + 1; - names[igroup] = new char[n]; - strcpy(names[igroup],name); + names[igroup] = utils::strdup(name); ngroup++; } @@ -602,9 +595,7 @@ int Group::find_or_create(const char *name) if (ngroup == MAX_GROUP) error->all(FLERR,"Too many groups"); igroup = find_unused(); - int n = strlen(name) + 1; - names[igroup] = new char[n]; - strcpy(names[igroup],name); + names[igroup] = utils::strdup(name); ngroup++; return igroup;