[PATCH v2 01/32] Introduce make_unique_xstrndup
Simon Marchi
simark@simark.ca
Fri Nov 5 19:20:31 GMT 2021
On 2021-11-04 2:08 p.m., Tom Tromey wrote:
> This adds a new make_unique_xstrndup function, which is the "n"
> analogue of make_unique_xstrdup. This is used by later patches.
> ---
> gdbsupport/gdb_unique_ptr.h | 9 +++++++++
> 1 file changed, 9 insertions(+)
>
> diff --git a/gdbsupport/gdb_unique_ptr.h b/gdbsupport/gdb_unique_ptr.h
> index df88cea9cf0..77aecb48e62 100644
> --- a/gdbsupport/gdb_unique_ptr.h
> +++ b/gdbsupport/gdb_unique_ptr.h
> @@ -64,4 +64,13 @@ make_unique_xstrdup (const char *str)
> return gdb::unique_xmalloc_ptr<char> (xstrdup (str));
> }
>
> +/* Dup the first N characters of STR and return a unique_xmalloc_ptr
> + for the result. The result is always \0-terminated. */
> +
> +static inline gdb::unique_xmalloc_ptr<char>
> +make_unique_xstrndup (const char *str, size_t n)
> +{
> + return gdb::unique_xmalloc_ptr<char> (xstrndup (str, n));
> +}
> +
> #endif /* COMMON_GDB_UNIQUE_PTR_H */
> --
> 2.31.1
>
I found one spot where you could use this, in cli/cli-setshow.exp. I think
that if the new function is used, this patch could be pushed right away.
Simon
More information about the Gdb-patches
mailing list