This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH 08/18] malloc: Add specialized dynarray for C strings
- From: Florian Weimer <fweimer at redhat dot com>
- To: Adhemerval Zanella <adhemerval dot zanella at linaro dot org>, libc-alpha at sourceware dot org
- Date: Thu, 17 Aug 2017 12:12:47 +0200
- Subject: Re: [PATCH 08/18] malloc: Add specialized dynarray for C strings
- Authentication-results: sourceware.org; auth=none
- Authentication-results: ext-mx08.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com
- Authentication-results: ext-mx08.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=fweimer at redhat dot com
- Dmarc-filter: OpenDMARC Filter v1.3.2 mx1.redhat.com E788CC00B8E0
- References: <1502463044-4042-1-git-send-email-adhemerval.zanella@linaro.org> <1502463044-4042-9-git-send-email-adhemerval.zanella@linaro.org>
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