| 60 | } |
| 61 | |
| 62 | const char* getUnits(const char* string, S32 startIndex, S32 endIndex, const char* set) |
| 63 | { |
| 64 | // [neo, 5/11/2007 - #2998] |
| 65 | // Range check |
| 66 | if( startIndex > endIndex ) |
| 67 | return ""; |
| 68 | |
| 69 | S32 sz; |
| 70 | S32 index = startIndex; |
| 71 | while(index--) |
| 72 | { |
| 73 | if(!*string) |
| 74 | return ""; |
| 75 | sz = dStrcspn(string, set); |
| 76 | if (string[sz] == 0) |
| 77 | return ""; |
| 78 | string += (sz + 1); |
| 79 | } |
| 80 | const char *startString = string; |
| 81 | while(startIndex <= endIndex--) |
| 82 | { |
| 83 | sz = dStrcspn(string, set); |
| 84 | string += sz; |
| 85 | if (*string == 0) |
| 86 | break; |
| 87 | string++; |
| 88 | } |
| 89 | if(!*string) |
| 90 | string++; |
| 91 | |
| 92 | // [neo, 5/11/2007 - #2998] |
| 93 | // Another case of the U32 wrapping from 0 to boom! If totalSize < 0 it will |
| 94 | // wrap to somewhere around U32 max and that is a lot for dStrncpy to overrun! |
| 95 | //U32 totalSize = (U32(string - startString)); |
| 96 | S32 totalSize = (S32)(string - startString); |
| 97 | |
| 98 | AssertFatal( totalSize < sizeof( _returnBuffer ), "Size of returned string too large for return buffer" ); |
| 99 | |
| 100 | if( totalSize > 0 ) |
| 101 | { |
| 102 | char *ret = &_returnBuffer[0]; |
| 103 | dStrncpy(ret, startString, totalSize - 1); |
| 104 | ret[totalSize-1] = '\0'; |
| 105 | |
| 106 | return ret; |
| 107 | } |
| 108 | |
| 109 | return ""; |
| 110 | } |
| 111 | |
| 112 | U32 getUnitCount(const char *string, const char *set) |
| 113 | { |
no test coverage detected