Branch: Tag:

2014-08-18

2014-08-18 10:20:35 by Henrik Grubbström (Grubba) <grubba@grubba.org>

Strings: Survive xalloc() throwing errors in realloc.

Short string contents would be passed to free(3C) if the
call to xalloc() failed.

Same for truncating strings if ba_alloc() ever starts throwing
errors instead of fatals.

1644:    break;    case 1: { // old string was short    size_t obytes = (size_t)(a->len+1) << a->size_shift; -  a->flags &= ~STRING_IS_SHORT; +     s = xalloc(nbytes); -  +  a->flags &= ~STRING_IS_SHORT;    memcpy(s, a->str, obytes);    ba_free(&string_allocator, a->str);    break;    }    case 2: // new string is short -  a->flags |= STRING_IS_SHORT; +     s = ba_alloc(&string_allocator); -  +  a->flags |= STRING_IS_SHORT;    memcpy(s, a->str, nbytes);    free(a->str);    break;