Changeset 6278
- Timestamp:
- Feb 1, 2006, 10:40:56 AM (20 years ago)
- Location:
- trunk/psLib
- Files:
-
- 5 edited
-
src/sys/psString.c (modified) (6 diffs)
-
src/sys/psString.h (modified) (3 diffs)
-
src/types/psMetadata.c (modified) (2 diffs)
-
test/sys/tst_psString.c (modified) (4 diffs)
-
test/sys/verified/tst_psString.stderr (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/sys/psString.c
r6218 r6278 13 13 * @author David Robbins, MHPCC 14 14 * 15 * @version $Revision: 1.2 3$ $Name: not supported by cvs2svn $16 * @date $Date: 2006-0 1-27 01:49:05$15 * @version $Revision: 1.24 $ $Name: not supported by cvs2svn $ 16 * @date $Date: 2006-02-01 20:40:56 $ 17 17 * 18 18 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 31 31 psString psStringCopy(const char *string) 32 32 { 33 PS_ASSERT_PTR_NON_NULL(string, NULL); 33 34 // Allocate memory using psAlloc function 34 35 // Copy input string to memory just allocated 35 36 // 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; 37 39 } 38 40 … … 40 42 unsigned int nChar) 41 43 { 44 PS_ASSERT_PTR_NON_NULL(string, NULL); 42 45 char *returnValue = NULL; 43 46 … … 53 56 // Copy input string to memory allocated up to nChar characters 54 57 // 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; 56 62 57 63 // Ensure the last byte is NULL character … … 66 72 ...) 67 73 { 74 PS_ASSERT_PTR_NON_NULL(format, 0); 68 75 va_list args; 69 76 size_t length; // complete string length (sans \0) … … 113 120 ...) 114 121 { 122 PS_ASSERT_PTR_NON_NULL(format, 0); 115 123 va_list args; 116 124 size_t length; // complete string length (sans \0) -
trunk/psLib/src/sys/psString.h
r6201 r6278 14 14 * @author David Robbins, MHPCC 15 15 * 16 * @version $Revision: 1.1 7$ $Name: not supported by cvs2svn $17 * @date $Date: 2006-0 1-26 05:31:54$16 * @version $Revision: 1.18 $ $Name: not supported by cvs2svn $ 17 * @date $Date: 2006-02-01 20:40:56 $ 18 18 * 19 19 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 38 38 /** Copies the input string 39 39 * 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. 42 43 * 43 44 * @return psString: Copy of input string … … 55 56 * string will be a substring of the input string. If the input string 56 57 * 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. 58 59 * 59 60 * @return psString: Copy of input string -
trunk/psLib/src/types/psMetadata.c
r6251 r6278 12 12 * @author Ross Harman, MHPCC 13 13 * 14 * @version $Revision: 1.9 7$ $Name: not supported by cvs2svn $15 * @date $Date: 2006-0 1-30 20:28:33$14 * @version $Revision: 1.98 $ $Name: not supported by cvs2svn $ 15 * @date $Date: 2006-02-01 20:40:56 $ 16 16 * 17 17 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 264 264 case PS_DATA_STRING: 265 265 // Perform copy of input strings 266 metadataItem->data.V = psStringNCopy(va_arg(argPtr, char *), MAX_STRING_LENGTH); 266 { 267 char *string = va_arg(argPtr, char *); 268 metadataItem->data.V = 269 string ? psStringNCopy(string, MAX_STRING_LENGTH) 270 : NULL; 271 } 267 272 break; 268 273 case PS_DATA_ARRAY: // psArray -
trunk/psLib/test/sys/tst_psString.c
r6218 r6278 20 20 * @author Eric Van Alst, MHPCC 21 21 * 22 * @version $Revision: 1. 3$ $Name: not supported by cvs2svn $23 * @date $Date: 2006-0 1-27 01:49:05$22 * @version $Revision: 1.4 $ $Name: not supported by cvs2svn $ 23 * @date $Date: 2006-02-01 20:40:56 $ 24 24 * 25 25 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 52 52 53 53 static psS32 testStrSplit00(void); 54 static psS32 testNULLStrings(void); 54 55 55 56 testDescription tests[] = { … … 72 73 {testStrPrepend03,14, "Test prepend null-op", 0, false}, 73 74 {testStrSplit00,15, "Test String Splitting", 0, false}, 75 {testNULLStrings,666, "Test NULL String Error Handling", 0, false}, 74 76 {NULL} 75 77 }; … … 619 621 } 620 622 623 static psS32 testNULLStrings(void) 624 { 625 psString nullTest = NULL; 626 psString output = NULL; 627 ssize_t outSize = 0; 628 char** nullDest = NULL; 629 char** test; 630 //psStringCopy should return NULL for NULL input string 631 psLogMsg(__func__,PS_LOG_INFO,"Following should generate error message"); 632 output = psStringCopy(nullTest); 633 if (output != NULL) { 634 psError(PS_ERR_BAD_PARAMETER_NULL, false, 635 "psStringCopy failed to return NULL for NULL input string.\n"); 636 return 1; 637 } 638 //psStringNCopy should return NULL for NULL input string 639 psLogMsg(__func__,PS_LOG_INFO,"Following should generate error message"); 640 output = psStringNCopy(nullTest, 100); 641 if (output != NULL) { 642 psError(PS_ERR_BAD_PARAMETER_NULL, false, 643 "psStringNCopy failed to return NULL for NULL input string.\n"); 644 return 2; 645 } 646 647 //psStringAppend should return 0 for NULL input destination 648 outSize = psStringAppend(nullDest, ""); 649 if (outSize != 0) { 650 psError(PS_ERR_BAD_PARAMETER_NULL, false, 651 "psStringAppend failed to return 0 for NULL input destination.\n"); 652 return 3; 653 } 654 //psStringAppend should return 0 for NULL input format 655 psLogMsg(__func__,PS_LOG_INFO,"Following should generate error message"); 656 outSize = psStringAppend(test, nullTest); 657 if (outSize != 0) { 658 psError(PS_ERR_BAD_PARAMETER_NULL, false, 659 "psStringAppend failed to return 0 for NULL input format.\n"); 660 return 4; 661 } 662 //psStringPrepend should return 0 for NULL input destination 663 outSize = psStringPrepend(nullDest, " "); 664 if (outSize != 0) { 665 psError(PS_ERR_BAD_PARAMETER_NULL, false, 666 "psStringPrepend failed to return 0 for NULL input destination.\n"); 667 return 3; 668 } 669 //psStringPrepend should return 0 for NULL input format 670 psLogMsg(__func__,PS_LOG_INFO,"Following should generate error message"); 671 outSize = psStringPrepend(test, nullTest); 672 if (outSize != 0) { 673 psError(PS_ERR_BAD_PARAMETER_NULL, false, 674 "psStringPrepend failed to return 0 for NULL input format.\n"); 675 return 4; 676 } 677 //psStringSplit should return NULL for NULL input string 678 psList *nullList = NULL; 679 psLogMsg(__func__,PS_LOG_INFO,"Following should generate error message"); 680 nullList = psStringSplit(nullTest, ","); 681 if (nullList != NULL) { 682 psError(PS_ERR_BAD_PARAMETER_NULL, false, 683 "psStringSplit failed to return NULL for NULL input string.\n"); 684 return 5; 685 } 686 //psStringSplit should return NULL for NULL input splitter 687 psLogMsg(__func__,PS_LOG_INFO,"Following should generate error message"); 688 nullList = psStringSplit("Hello World", nullTest); 689 if (nullList != NULL) { 690 psError(PS_ERR_BAD_PARAMETER_NULL, false, 691 "psStringSplit failed to return NULL for NULL input splitter.\n"); 692 return 6; 693 } 694 695 return 0; 696 } 697 -
trunk/psLib/test/sys/verified/tst_psString.stderr
r6218 r6278 68 68 \**********************************************************************************/ 69 69 70 <DATE><TIME>|<HOST>|E|psStringAppend (FILE:LINENO) 71 Unallowable operation: format is NULL. 72 <DATE><TIME>|<HOST>|E|psStringAppend (FILE:LINENO) 73 Unallowable operation: format is NULL. 70 74 71 75 ---> TESTPOINT PASSED (psString{Test append NULL handling} | tst_psString.c) … … 104 108 \**********************************************************************************/ 105 109 110 <DATE><TIME>|<HOST>|E|psStringPrepend (FILE:LINENO) 111 Unallowable operation: format is NULL. 112 <DATE><TIME>|<HOST>|E|psStringPrepend (FILE:LINENO) 113 Unallowable operation: format is NULL. 106 114 107 115 ---> TESTPOINT PASSED (psString{Test prepend NULL handling} | tst_psString.c) … … 146 154 ---> TESTPOINT PASSED (psString{Test String Splitting} | tst_psString.c) 147 155 156 /***************************** TESTPOINT ******************************************\ 157 * TestFile: tst_psString.c * 158 * TestPoint: psString{Test NULL String Error Handling} * 159 * TestType: Positive * 160 \**********************************************************************************/ 161 162 <DATE><TIME>|<HOST>|I|testNULLStrings 163 Following should generate error message 164 <DATE><TIME>|<HOST>|E|psStringCopy (FILE:LINENO) 165 Unallowable operation: string is NULL. 166 <DATE><TIME>|<HOST>|I|testNULLStrings 167 Following should generate error message 168 <DATE><TIME>|<HOST>|E|psStringNCopy (FILE:LINENO) 169 Unallowable operation: string is NULL. 170 <DATE><TIME>|<HOST>|I|testNULLStrings 171 Following should generate error message 172 <DATE><TIME>|<HOST>|E|psStringAppend (FILE:LINENO) 173 Unallowable operation: format is NULL. 174 <DATE><TIME>|<HOST>|I|testNULLStrings 175 Following should generate error message 176 <DATE><TIME>|<HOST>|E|psStringPrepend (FILE:LINENO) 177 Unallowable operation: format is NULL. 178 <DATE><TIME>|<HOST>|I|testNULLStrings 179 Following should generate error message 180 <DATE><TIME>|<HOST>|E|psStringSplit (FILE:LINENO) 181 Unallowable operation: string is NULL. 182 <DATE><TIME>|<HOST>|I|testNULLStrings 183 Following should generate error message 184 <DATE><TIME>|<HOST>|E|psStringSplit (FILE:LINENO) 185 Unallowable operation: splitters is NULL. 186 187 ---> TESTPOINT PASSED (psString{Test NULL String Error Handling} | tst_psString.c) 188
Note:
See TracChangeset
for help on using the changeset viewer.
