267 *n = 0; |
267 *n = 0; |
268 return NULL; |
268 return NULL; |
269 } else /* no match possible */ { |
269 } else /* no match possible */ { |
270 *n = 1; |
270 *n = 1; |
271 sstr_t *result = (sstr_t*) almalloc(allocator, sizeof(sstr_t)); |
271 sstr_t *result = (sstr_t*) almalloc(allocator, sizeof(sstr_t)); |
272 *result = sstrdup_a(allocator, s); |
272 if(result) { |
|
273 *result = sstrdup_a(allocator, s); |
|
274 } else { |
|
275 *n = -2; |
|
276 } |
273 return result; |
277 return result; |
274 } |
278 } |
275 } |
279 } |
276 |
280 |
277 ssize_t nmax = *n; |
281 ssize_t nmax = *n; |
278 size_t arrlen = 16; |
282 size_t arrlen = 16; |
279 sstr_t* result = (sstr_t*) almalloc(allocator, arrlen*sizeof(sstr_t)); |
283 sstr_t* result = (sstr_t*) alcalloc(allocator, arrlen, sizeof(sstr_t)); |
280 |
284 |
281 if (result) { |
285 if (result) { |
282 sstr_t curpos = s; |
286 sstr_t curpos = s; |
283 ssize_t j = 1; |
287 ssize_t j = 1; |
284 while (1) { |
288 while (1) { |
308 |
312 |
309 /* allocate memory for the next string */ |
313 /* allocate memory for the next string */ |
310 j++; |
314 j++; |
311 if (j > arrlen) { |
315 if (j > arrlen) { |
312 arrlen *= 2; |
316 arrlen *= 2; |
313 sstr_t* reallocated = (sstr_t*) alrealloc( |
317 size_t reallocsz; |
314 allocator, result, arrlen*sizeof(sstr_t)); |
318 sstr_t* reallocated = NULL; |
|
319 if(!ucx_szmul(arrlen, sizeof(sstr_t), &reallocsz)) { |
|
320 reallocated = (sstr_t*) alrealloc( |
|
321 allocator, result, reallocsz); |
|
322 } |
315 if (reallocated) { |
323 if (reallocated) { |
316 result = reallocated; |
324 result = reallocated; |
317 } else { |
325 } else { |
318 for (ssize_t i = 0 ; i < j-1 ; i++) { |
326 for (ssize_t i = 0 ; i < j-1 ; i++) { |
319 alfree(allocator, result[i].ptr); |
327 alfree(allocator, result[i].ptr); |