This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [PATCH 4/4] Introduce obstack_strndup
On Sat, 3 Aug 2019 20:51:10 -0600
Tom Tromey <tom@tromey.com> wrote:
> This introduces obstack_strndup and changes gdb to use it.
>
> Note that obstack_strndup works like savestring, and not exactly like
> xstrndup -- so perhaps it is misnamed, or perhaps it ought to be
> changed. The difference is that obstack_strndup uses the passed-in
> length, while xstrndup uses strnlen to choose the length.
>
> gdb/ChangeLog
> 2019-08-03 Tom Tromey <tom@tromey.com>
>
> * stabsread.c (patch_block_stabs, read_one_struct_field)
> (read_enum_type): Use obstack_strndup.
> * rust-exp.y (rust_parser::copy_name): Use obstack_strndup.
> * gdb_obstack.h (obstack_strndup): Use obstack_strndup.
> * dwarf2read.c (guess_full_die_structure_name)
> (anonymous_struct_prefix): Use obstack_strndup.
> * dbxread.c (cp_set_block_scope): Use obstack_strndup.
> * c-exp.y (yylex): Use obstack_strndup.
> * ada-exp.y (write_object_renaming, write_ambiguous_var)
> (write_var_or_type): Use obstack_strndup.
I think the name (of obstack_strndup) is okay, though I do think that
it might be worth noting that exactly N characters are duplicated in
obstack_strndup's comment. I.e, it won't be shorter if the string
being copied happens to be shorter.
It took me a while to realize that the "0" in obstack_copy0 /
obstack_grow0 cause a '\0' character to be tacked onto the end.
Anyway, aside from perhaps updating the comment for obstack_strndup, it
looks good to me.
Kevin