diff options
author | tradke <tradke@17b73243-c579-4c4c-a9d2-2d5706c11dac> | 2003-02-11 15:11:43 +0000 |
---|---|---|
committer | tradke <tradke@17b73243-c579-4c4c-a9d2-2d5706c11dac> | 2003-02-11 15:11:43 +0000 |
commit | 503a59f91ca7573b555686c48e3e187316e7ac76 (patch) | |
tree | db9fe11a42694f42ae766204b78fe63db2b79fda /src/main/MainUtils.c | |
parent | ccb62ea57954c161f61ccc42016b467739d63fed (diff) |
Make sure that strncpy'ed strings are properly NUL-terminated.
git-svn-id: http://svn.cactuscode.org/flesh/trunk@3133 17b73243-c579-4c4c-a9d2-2d5706c11dac
Diffstat (limited to 'src/main/MainUtils.c')
-rw-r--r-- | src/main/MainUtils.c | 101 |
1 files changed, 29 insertions, 72 deletions
diff --git a/src/main/MainUtils.c b/src/main/MainUtils.c index b71a145b..0723e665 100644 --- a/src/main/MainUtils.c +++ b/src/main/MainUtils.c @@ -2,17 +2,15 @@ @file MainUtils.c @date Sep 22 1999 @author Thomas Radke, Gabrielle Allen - @desc - Utility Flesh routines - @enddesc - @version $Header$ + @desc + Utility Flesh routines + @enddesc + @version $Id$ @@*/ #include <string.h> #include "cctk_Flesh.h" -#include "cctk_Misc.h" -#include "cctk_Schedule.h" #include "cctk_Parameter.h" static const char *rcsid = "$Header$"; @@ -20,91 +18,50 @@ static const char *rcsid = "$Header$"; CCTK_FILEVERSION(main_MainUtils_c); /******************************************************************** - ********************* Local Data Types *********************** - ********************************************************************/ - -/******************************************************************** - ********************* Local Routine Prototypes ********************* + ********************* External Routine Prototypes ****************** ********************************************************************/ int CCTK_RunTitle(int len, char *title); -/******************************************************************** - ********************* Other Routine Prototypes ********************* - ********************************************************************/ - -/******************************************************************** - ********************* Local Data ***************************** - ********************************************************************/ - -/******************************************************************** - ********************* External Routines ********************** - ********************************************************************/ /*@@ @routine CCTK_RunTitle @date Sun Sep 17 2000 @author Gabrielle Allen - @desc - Returns the simulation description - @enddesc - @calls - @calledby - @history - - @endhistory - @var len - @vdesc The length of the title buffer - @vtype int - @vio in - @vcomment - - @endvar - @var title - @vdesc The title buffer - @vtype char * - @vio out - @vcomment - - @endvar + @desc + Returns the simulation description + @enddesc + + @var len + @vdesc The size (in characters) of the title buffer + @vtype int + @vio in + @endvar + @var title + @vdesc The title buffer + @vtype char * + @vio out + @endvar @returntype int - @returndesc - The length of the title - - if title is NULL + @returndesc + The length of the (copied) title, or<BR> + -1 if parameter value of "Cactus::cctk_run_title" is unknown @endreturndesc @@*/ int CCTK_RunTitle(int len, char *title) { - int retval; - int param_type; + int retval; const char *cctk_title; - cctk_title = (*(const char **) - CCTK_ParameterGet("cctk_run_title", - "Cactus", - ¶m_type)); - + retval = -1; + + cctk_title = *(const char **) + CCTK_ParameterGet("cctk_run_title", "Cactus", NULL); if (cctk_title) { - if (CCTK_Equals(cctk_title,"")) - { - strncpy(title,"Cactus Simulation",len-1); - } - else - { - strncpy(title,cctk_title,len-1); - } + strncpy (title, *cctk_title ? cctk_title : "Cactus Simulation", len-1); + title[len-1] = 0; retval = strlen(title); - retval=retval > len ? 0 : retval; - } - else - { - retval = -1; } return retval; } - -/******************************************************************** - ********************* Local Routines ************************* - ********************************************************************/ - |