diff options
author | tradke <tradke@b32723a9-ab3a-4a60-88e2-2e5d99d7c17a> | 2003-01-06 12:28:42 +0000 |
---|---|---|
committer | tradke <tradke@b32723a9-ab3a-4a60-88e2-2e5d99d7c17a> | 2003-01-06 12:28:42 +0000 |
commit | a14b46a5092104e75822b605d3ad46b51702298f (patch) | |
tree | 1276cad97956de9756879eeffa34eda18c5e5f36 | |
parent | cc43b1f4fa1a197f757ff260673eb2b74a110c8b (diff) |
Copy pointers to string parameters to a local variable before modifying it.
This prevents potential future problems in pointer assignments when we declare
a pointer to a string parameters constant.
This closes Cactus/1350.
git-svn-id: http://svn.cactuscode.org/arrangements/CactusBase/IOUtil/trunk@180 b32723a9-ab3a-4a60-88e2-2e5d99d7c17a
-rw-r--r-- | src/Startup.c | 36 |
1 files changed, 20 insertions, 16 deletions
diff --git a/src/Startup.c b/src/Startup.c index 618a106..3e29dcc 100644 --- a/src/Startup.c +++ b/src/Startup.c @@ -705,6 +705,7 @@ static int CopyParFile (int recovered) { int in_parfile, out_parfile, bytes, flags; char *out_parfilename, buffer[256]; + const char *my_parfile_name; struct stat in_stat_buf, out_stat_buf; DECLARE_CCTK_PARAMETERS @@ -726,21 +727,22 @@ static int CopyParFile (int recovered) } /* build the name of the output parfile */ - if (! *parfile_name) + my_parfile_name = parfile_name; + if (! *my_parfile_name) { /* cut off any path names */ - parfile_name = strrchr (buffer, '/'); - if (parfile_name) + my_parfile_name = strrchr (buffer, '/'); + if (my_parfile_name) { - parfile_name++; + my_parfile_name++; } else { - parfile_name = buffer; + my_parfile_name = buffer; } } - out_parfilename = (char *) malloc (strlen(out_dir) + strlen(parfile_name)+2); - sprintf (out_parfilename, "%s/%s", out_dir, parfile_name); + out_parfilename = malloc (strlen (out_dir) + strlen (my_parfile_name) + 2); + sprintf (out_parfilename, "%s/%s", out_dir, my_parfile_name); /* check whether input and output files are identical */ if (! stat (out_parfilename, &out_stat_buf) && @@ -749,7 +751,7 @@ static int CopyParFile (int recovered) CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, "Parameter file '%s' to be written into directory '%s' is " "identical with original parameter file. Parameter file will " - "not be copied.", parfile_name, out_dir); + "not be copied.", my_parfile_name, out_dir); out_parfile = 0; } else @@ -818,6 +820,7 @@ static int GenerateParFile (int recovered) FILE *outfile; int out_parfile, flags; char *out_parfilename, buffer[256]; + const char *my_parfile_name; struct stat in_stat_buf, out_stat_buf; DECLARE_CCTK_PARAMETERS @@ -833,21 +836,22 @@ static int GenerateParFile (int recovered) } /* build the name of the output parfile */ - if (! *parfile_name) + my_parfile_name = parfile_name; + if (! *my_parfile_name) { /* cut off any path names */ - parfile_name = strrchr (buffer, '/'); - if (parfile_name) + my_parfile_name = strrchr (buffer, '/'); + if (my_parfile_name) { - parfile_name++; + my_parfile_name++; } else { - parfile_name = buffer; + my_parfile_name = buffer; } } - out_parfilename = (char *) malloc (strlen(out_dir) + strlen(parfile_name)+2); - sprintf (out_parfilename, "%s/%s", out_dir, parfile_name); + out_parfilename = malloc (strlen (out_dir) + strlen (my_parfile_name) + 2); + sprintf (out_parfilename, "%s/%s", out_dir, my_parfile_name); /* check whether input and output files are identical */ if (! stat (out_parfilename, &out_stat_buf) && @@ -856,7 +860,7 @@ static int GenerateParFile (int recovered) CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, "Parameter file '%s' to be written into directory '%s' is " "identical with original parameter file. Parameter file will " - "not be generated.", parfile_name, out_dir); + "not be generated.", my_parfile_name, out_dir); out_parfile = 0; } else |