[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: RFC: add a string-desc module
From: |
Vivien Kraus |
Subject: |
Re: RFC: add a string-desc module |
Date: |
Sat, 25 Mar 2023 07:25:20 +0100 |
User-agent: |
Evolution 3.46.0 |
Le vendredi 24 mars 2023 à 19:20 -0400, Jeffrey Walton a écrit :
> The type that I'm proposing does not have NUL byte appended to the
> data
> > always and automatically, because I think it is more important to
> > have a
> > string_desc_substring function that does not cause memory
> > allocation,
> > than to have string_desc_c function (conversion to 'char *') that
> > does
> > not cause memory allocation.
>
> I would take caution if not including a NULL. A natural thing to want
> to do is print a string, and C-based routines usually expect a
> terminating NULL.
>
> Also, if you initialize the struct, then the allocated string will
> likely include a terminating NULL. I understand the size member will
> omit the NULL, but it will be present anyways in the string. (Unless
> you do something ugly, like spell out the characters of the string).
>From what I understand, the proposed substring function cannot add a
NUL byte without doing a copy first.
Vivien