X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-http;a=blobdiff_plain;f=phpstr%2Fphpstr.c;fp=phpstr%2Fphpstr.c;h=4eaec1c0a9a300365ec1252a79f9944d3aef6e93;hp=a312b1e773134dbe2ad558aeaaffaa78ff1ec38b;hb=31092c29dba06404d2f0d856d5a89f0b28be6f0b;hpb=e617c45f50c2233376a2cac393da1f0d03965a5c diff --git a/phpstr/phpstr.c b/phpstr/phpstr.c index a312b1e..4eaec1c 100644 --- a/phpstr/phpstr.c +++ b/phpstr/phpstr.c @@ -34,7 +34,7 @@ PHPSTR_API phpstr *phpstr_from_string_ex(phpstr *buf, const char *string, size_t return buf; } -PHPSTR_API size_t phpstr_resize_ex(phpstr *buf, size_t len, size_t override_size) +PHPSTR_API size_t phpstr_resize_ex(phpstr *buf, size_t len, size_t override_size, int allow_error) { #if 0 fprintf(stderr, "RESIZE: size=%lu, used=%lu, free=%lu\n", buf->size, buf->used, buf->free); @@ -46,7 +46,13 @@ PHPSTR_API size_t phpstr_resize_ex(phpstr *buf, size_t len, size_t override_size size *= 2; } if (buf->data) { - char *ptr = perealloc(buf->data, buf->used + buf->free + size, buf->pmem); + char *ptr; + + if (allow_error) { + ptr = perealloc_recoverable(buf->data, buf->used + buf->free + size, buf->pmem); + } else { + ptr = perealloc(buf->data, buf->used + buf->free + size, buf->pmem); + } if (ptr) { buf->data = ptr; @@ -279,7 +285,7 @@ PHPSTR_API phpstr *phpstr_merge(unsigned argc, ...) PHPSTR_API phpstr *phpstr_fix(phpstr *buf) { - if (NOMEM == phpstr_resize_ex(buf, 1, 1)) { + if (NOMEM == phpstr_resize_ex(buf, 1, 1, 0)) { return NULL; } buf->data[buf->used] = '\0';