Branch: Tag:


2014-09-10 08:24:00 by Henrik Grubbström (Grubba) <>

Revert "Store new malloced value instead."

This reverts commit a9693064380ac62005cdd28f22b447902644a72f.

As mentioned in [LysLysKOM 20949405] (which probably hasn't been
exported correctly to the mailinglist yet):

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.

3143:   PMOD_EXPORT struct pike_string *finish_string_builder(struct string_builder *s)   {    ptrdiff_t len = s->s->len; -  if (len != s->malloced) -  s->s = realloc_unlinked_string(s->s, s->malloced = len); +  if (len != s->malloced) { +  s->s->len = s->malloced; +  s->s = realloc_unlinked_string(s->s, len); +  }    if(s->known_shift == s->s->size_shift)    return low_end_shared_string(s->s);    return end_shared_string(s->s);