Re: [PATCH v1 03/10] target_fileio_read_stralloc: add an optional length parameter
Matthieu Longo <[email protected]> Mon, 27 Jul 2026 15:48:00 +0100
| Newsgroups | gmane.comp.gdb.patches |
|---|---|
| Message-ID | <[email protected]> |
On 21/07/2026 22:28, Luis wrote:
> Empty commit message...
>
> On 07/07/2026 16:48, Matthieu Longo wrote:
>> ---
>> gdb/target.c | 10 +++++++---
>> gdb/target.h | 2 +-
>> 2 files changed, 8 insertions(+), 4 deletions(-)
>>
>> diff --git a/gdb/target.c b/gdb/target.c
>> index 5d937f3ae85..e4907ca815a 100644
>> --- a/gdb/target.c
>> +++ b/gdb/target.c
>> @@ -3547,7 +3547,8 @@ target_fileio_read_alloc (struct inferior *inf, const char *filename,
>> /* See target.h. */
>> gdb::unique_xmalloc_ptr<char>
>> -target_fileio_read_stralloc (struct inferior *inf, const char *filename)
>> +target_fileio_read_stralloc (struct inferior *inf, const char *filename,
>> + size_t *len)
>> {
>> gdb_byte *buffer;
>> char *bufstr;
>> @@ -3556,17 +3557,20 @@ target_fileio_read_stralloc (struct inferior *inf, const char *filename)
>> transferred = target_fileio_read_alloc_1 (inf, filename, &buffer, 1);
>> bufstr = (char *) buffer;
>> + if (len != nullptr)
>> + *len = (transferred < 0 ? 0 : transferred);
>> +
>> if (transferred < 0)
>> return gdb::unique_xmalloc_ptr<char> (nullptr);
>> if (transferred == 0)
>> return make_unique_xstrdup ("");
>> - bufstr[transferred] = 0;
>> + bufstr[transferred] = '\0';
>
> Why 0 -> \0?
>
The null byte is set at the end of the string.
The null byte is usually noted as '\0'.
I replace the usage of 0 by '\0'.
Is there an issue with this ?
>> /* Check for embedded NUL bytes; but allow trailing NULs. */
>> for (i = strlen (bufstr); i < transferred; i++)
>> - if (bufstr[i] != 0)
>> + if (bufstr[i] != '\0')
>
> Likewise, why 0 -> \0?
>
Same answer here.
Matthieu