[PATCH 08/18] malloc: Add specialized dynarray for C strings
Florian Weimer
fweimer@redhat.com
Thu Aug 17 10:12:00 GMT 2017
On 08/11/2017 04:50 PM, Adhemerval Zanella wrote:
> This patch adds an specialized dynarray to manage C strings using the
> dynarray internal implementation. It uses some private fields from
> dynarray and thus it provided specific files to access and manage
> the internal string buffer.
There is a lot of complexity in this code to maintain the invariant that
the stored array is NUL-terminated. It also means that the dynarray
functions must not be used directly.
std::string in C++ has a c_str() method which adds the null termination
on demand. This means that char_array_str could fail due to memory
allocation, but I think it would simplify the code in general. I tried
to write the dynarray functions in such a way that errors are sticky, so
one error check (char_array_str returns NULL) could cover all the
previous manipulations.
Thanks,
Florian
More information about the Libc-alpha
mailing list