While "browsing" some code (what else to do with your spare time ;-), I find (not committed yet):
:-)
diff --git a/src/stralloc.c b/src/stralloc.c index 7cd709c..6ca0a02 100644 --- a/src/stralloc.c +++ b/src/stralloc.c @@ -3221,10 +3221,8 @@ PMOD_EXPORT void free_string_builder(struct string_builder *s) PMOD_EXPORT struct pike_string *finish_string_builder(struct string_builder *s) { ptrdiff_t len = s->s->len;
- if (len != s->malloced) {
- s->s->len = s->malloced;
- s->s = realloc_unlinked_string(s->s, len);
- }
- if (len != s->malloced)
- s->s = realloc_unlinked_string(s->s, s->malloced = len); else /* Ensure NUL-termination */ low_set_index(s->s,s->s->len,0);
Am I just reading this wrong, or was the len/malloced assignment the wrong way around? And if yes, does this have any noticeable impact on the rest of the system?
The old code looks correct to me.
* Restore s->s->len to the value it had when s->s was allocated (aka s->malloced).
* Reallocate s->s with the new (now known) final length.
The question does however arise whether the code is correct on realloc failure.
/grubba