Re: [PATCH v1 03/10] target_fileio_read_stralloc: add an optional length parameter
Luis <[email protected]> Tue, 21 Jul 2026 22:28:53 +0100
| Newsgroups | gmane.comp.gdb.patches |
|---|---|
| Message-ID | <[email protected]> |
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?
>
> /* 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?
> {
> warning (_("target file %s "
> "contained unexpected null characters"),
> diff --git a/gdb/target.h b/gdb/target.h
> index 22653138491..4215553033c 100644
> --- a/gdb/target.h
> +++ b/gdb/target.h
> @@ -2336,7 +2336,7 @@ extern LONGEST target_fileio_read_alloc (struct inferior *inf,
> are returned as allocated but empty strings. A warning is issued
> if the result contains any embedded NUL bytes. */
> extern gdb::unique_xmalloc_ptr<char> target_fileio_read_stralloc
> - (struct inferior *inf, const char *filename);
> + (struct inferior *inf, const char *filename, size_t *len = nullptr);
>
> /* Invalidate the target associated with open handles that were open
> on target TARG, since we're about to close (and maybe destroy) the