IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 6278 for trunk/psLib/src/sys


Ignore:
Timestamp:
Feb 1, 2006, 10:40:56 AM (20 years ago)
Author:
drobbin
Message:

Added error handling to psString for NULL string inputs.

Location:
trunk/psLib/src/sys
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/sys/psString.c

    r6218 r6278  
    1313 *  @author David Robbins, MHPCC
    1414 *
    15  *  @version $Revision: 1.23 $ $Name: not supported by cvs2svn $
    16  *  @date $Date: 2006-01-27 01:49:05 $
     15 *  @version $Revision: 1.24 $ $Name: not supported by cvs2svn $
     16 *  @date $Date: 2006-02-01 20:40:56 $
    1717 *
    1818 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    3131psString psStringCopy(const char *string)
    3232{
     33    PS_ASSERT_PTR_NON_NULL(string, NULL);
    3334    // Allocate memory using psAlloc function
    3435    // Copy input string to memory just allocated
    3536    // Return the copy
    36     return strcpy(psAlloc(strlen(string) + 1), string);
     37    // Pass through NULL values
     38    return string ? strcpy(psAlloc(strlen(string) + 1), string) : NULL;
    3739}
    3840
     
    4042                       unsigned int nChar)
    4143{
     44    PS_ASSERT_PTR_NON_NULL(string, NULL);
    4245    char *returnValue = NULL;
    4346
     
    5356    // Copy input string to memory allocated up to nChar characters
    5457    // Return the copy
    55     returnValue = strncpy(psAlloc((size_t) nChar + 1), string, (size_t) nChar);
     58    // Pass through NULL values
     59    returnValue =
     60              string ? strncpy(psAlloc((size_t) nChar + 1), string, (size_t) nChar)
     61              : NULL;
    5662
    5763    // Ensure the last byte is NULL character
     
    6672                       ...)
    6773{
     74    PS_ASSERT_PTR_NON_NULL(format, 0);
    6875    va_list         args;
    6976    size_t          length;             // complete string length (sans \0)
     
    113120                        ...)
    114121{
     122    PS_ASSERT_PTR_NON_NULL(format, 0);
    115123    va_list         args;
    116124    size_t          length;             // complete string length (sans \0)
  • trunk/psLib/src/sys/psString.h

    r6201 r6278  
    1414 *  @author David Robbins, MHPCC
    1515 *
    16  *  @version $Revision: 1.17 $ $Name: not supported by cvs2svn $
    17  *  @date $Date: 2006-01-26 05:31:54 $
     16 *  @version $Revision: 1.18 $ $Name: not supported by cvs2svn $
     17 *  @date $Date: 2006-02-01 20:40:56 $
    1818 *
    1919 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    3838/** Copies the input string
    3939 *
    40  *  This function shall allocate memory to the length of the input string
    41  *  plus one and copy the input string to the newly allocated memory.
     40 *  This function shall allocate memory to the length of the input string plus
     41 *  one and copy the input string to the newly allocated memory.  If 'string'
     42 *  is 'NULL' then 'NULL' is returned.
    4243 *
    4344 *  @return psString:      Copy of input string
     
    5556 *  string will be a substring of the input string.  If the input string
    5657 *  is smaller than nChar bytes then the remaining bytes allocated will
    57  *  be set to NULL.
     58 *  be set to NULL.  If 'string' is 'NULL' then 'NULL' is returned.
    5859 *
    5960 *  @return  psString:   Copy of input string
Note: See TracChangeset for help on using the changeset viewer.