IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 631


Ignore:
Timestamp:
May 10, 2004, 9:01:36 AM (22 years ago)
Author:
evanalst
Message:

Modified to ensure last byte of N-copy is a null character.

Location:
trunk/psLib/src
Files:
2 edited

Legend:

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

    r546 r631  
    88 *  @author Eric Van Alst, MHPCC
    99 *   
    10  *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
    11  *  @date $Date: 2004-04-28 22:20:22 $
     10 *  @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
     11 *  @date $Date: 2004-05-10 19:01:36 $
    1212 *
    1313 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    7272)
    7373{
     74    char *returnValue = NULL;
     75
    7476    // Check the number of characters to copy is non-negative
    7577    if ( nChar < 0 ) {
     
    8284    // Copy input string to memory allocated up to nChar characters
    8385    // Return the copy
    84     return strncpy(psAlloc((size_t)nChar + 1), str, (size_t)nChar);
     86    returnValue = strncpy(psAlloc((size_t)nChar + 1), str, (size_t)nChar);
     87
     88    // Ensure the last byte is NULL character
     89    if ( nChar > 0 ) {
     90        returnValue[nChar-1] = NULL;
     91    }
     92
     93    // Return the string pointer
     94    return returnValue;
    8595}
    8696
  • trunk/psLib/src/sysUtils/psString.c

    r546 r631  
    88 *  @author Eric Van Alst, MHPCC
    99 *   
    10  *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
    11  *  @date $Date: 2004-04-28 22:20:22 $
     10 *  @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
     11 *  @date $Date: 2004-05-10 19:01:36 $
    1212 *
    1313 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    7272)
    7373{
     74    char *returnValue = NULL;
     75
    7476    // Check the number of characters to copy is non-negative
    7577    if ( nChar < 0 ) {
     
    8284    // Copy input string to memory allocated up to nChar characters
    8385    // Return the copy
    84     return strncpy(psAlloc((size_t)nChar + 1), str, (size_t)nChar);
     86    returnValue = strncpy(psAlloc((size_t)nChar + 1), str, (size_t)nChar);
     87
     88    // Ensure the last byte is NULL character
     89    if ( nChar > 0 ) {
     90        returnValue[nChar-1] = NULL;
     91    }
     92
     93    // Return the string pointer
     94    return returnValue;
    8595}
    8696
Note: See TracChangeset for help on using the changeset viewer.