- // create new string
- cxmutstr result;
- result.ptr = cxMalloc(alloc, slen + 1);
- result.length = slen;
- if (result.ptr == NULL) abort();
+ // reallocate or create new string
+ if (str.ptr == NULL) {
+ str.ptr = cxMalloc(alloc, slen + 1);
+ } else {
+ str.ptr = cxRealloc(alloc, str.ptr, slen + 1);
+ }
+ if (str.ptr == NULL) abort();