[lammps-users] write_restart '%' bug

in lammps-23May07

--- write_restart.cpp.old 2007-06-11 13:02:49.000000000 -0500
+++ write_restart.cpp 2007-06-11 13:03:03.000000000 -0500
@@ -114,7 +114,7 @@
   if (me == 0) {
     char *hfile;
     if (multiproc) {
- char *hfile = new char[strlen(file) + 16];
+ hfile = new char[strlen(file) + 16];
       char *ptr = strchr(file,'%');
       *ptr = '\0';
       sprintf(hfile,"%s%s%s",file,"base",ptr+1);

BTW I think string hfile after:

hfile = new char[...]
sprintf(hfile, ...)

is not guaranteed to be zero-terminated.

Marcin

sprintf() does NULL-terminate its output string

Steve

Some time ago, when I was testing tool that converted lammps restart
file to other format,
I came across a small problem with filenames of restart files in
multiproc case, i.e. when % is used in the filename.

There are two variables "hfile" in one function.
I think the patch below (for 9Jul07) will explain it better than my description:

--- write_restart.cpp.orig 2007-07-11 16:16:43.000000000 -0500
+++ write_restart.cpp 2007-07-11 16:23:28.000000000 -0500
@@ -131,7 +131,7 @@
   if (me == 0) {
     char *hfile;
     if (multiproc) {
- char *hfile = new char[strlen(file) + 16];
+ hfile = new char[strlen(file) + 16];
       char *ptr = strchr(file,'%');
       *ptr = '\0';
       sprintf(hfile,"%s%s%s",file,"base",ptr+1);

Regards,
Marcin

yes - a small bug - I'll post a patch for this

Thanks,
Steve