IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

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

Added error handling to psString for NULL string inputs.

File:
1 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)
Note: See TracChangeset for help on using the changeset viewer.