IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ticket #681: pslib-0.9.99-null_string_handling.patch

File pslib-0.9.99-null_string_handling.patch, 3.2 KB (added by jhoblitt, 20 years ago)

patch to fix NULL string handling

  • src/sys/psString.c

    RCS file: /usr/local/cvs/repositories/pan-starrs/datasys/IPP/psLib/src/sys/psString.c,v
    retrieving revision 1.23
    diff -u -r1.23 psString.c
     
    3333    // Allocate memory using psAlloc function
    3434    // Copy input string to memory just allocated
    3535    // Return the copy
    36     return strcpy(psAlloc(strlen(string) + 1), string);
     36    // Pass through NULL values
     37    return string ? strcpy(psAlloc(strlen(string) + 1), string) : NULL;
    3738}
    3839
    3940psString psStringNCopy(const char *string,
     
    5253    // Allocate memory using psAlloc function - nChar bytes
    5354    // Copy input string to memory allocated up to nChar characters
    5455    // Return the copy
    55     returnValue = strncpy(psAlloc((size_t) nChar + 1), string, (size_t) nChar);
     56    // Pass through NULL values
     57    returnValue =
     58         string ? strncpy(psAlloc((size_t) nChar + 1), string, (size_t) nChar)
     59                : NULL;
    5660
    5761    // Ensure the last byte is NULL character
    5862    returnValue[nChar] = '\0';
  • src/sys/psString.h

    RCS file: /usr/local/cvs/repositories/pan-starrs/datasys/IPP/psLib/src/sys/psString.h,v
    retrieving revision 1.17
    diff -u -r1.17 psString.h
     
    3737
    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
    4445 */
     
    5455 *  so if the input string is larger than nChar characters the copied
    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
    6061 */
  • src/types/psMetadata.c

    RCS file: /usr/local/cvs/repositories/pan-starrs/datasys/IPP/psLib/src/types/psMetadata.c,v
    retrieving revision 1.96
    diff -u -r1.96 psMetadata.c
     
    243243        break;
    244244    case PS_DATA_STRING:
    245245        // Perform copy of input strings
    246         metadataItem->data.V = psStringNCopy(va_arg(argPtr, char *), MAX_STRING_LENGTH);
     246        {
     247            char *string = va_arg(argPtr, char *);
     248            metadataItem->data.V =
     249                          string ? psStringNCopy(string, MAX_STRING_LENGTH)
     250                                 : NULL;
     251        }
    247252        break;
    248253    case     PS_DATA_ARRAY:                     // psArray
    249254    case     PS_DATA_BITSET:                    // psBitSet