Posted to tcl by gps at Sun Feb 15 21:06:58 GMT 2009view raw
- Before the realloc branch I'd try something like this pattern:
- char isSame = 0; /*Tcl_Bool would be nice. */
- int oldNumChars = 0;
- if (stringPtr->unicode == unicode) {
- isSame = 1;
- oldNumChar = stringPtr->numChars;
- }
- /* [realloc as needed] */
- if(isSame) {
- memcpy(stringPtr->unicode + oldNumChars, stringPtr->unicode, appendNumChars * sizeof(*unicode));
- } else {
- memcpy(...);
- }
- That assumes that unicode will have the same offset/pointer as the head of the Tcl_Obj. Is that valid?
- Regarding this:
- /* TODO: overflow check */
- numChars = stringPtr->numChars + appendNumChars;
- You can do:
- if((INT_MAX - stringPtr->numChars) < appendNumChars)
- /* handle overflow*/