mirror of
https://github.com/espressif/binutils-gdb.git
synced 2025-06-21 02:24:17 +08:00
Introduce make_unique_xstrndup
This adds a new make_unique_xstrndup function, which is the "n" analogue of make_unique_xstrdup. It also updates a couple existing places to use this function.
This commit is contained in:
@ -375,14 +375,13 @@ do_set_command (const char *arg, int from_tty, struct cmd_list_element *c)
|
|||||||
{
|
{
|
||||||
/* Clear trailing whitespace of filename. */
|
/* Clear trailing whitespace of filename. */
|
||||||
const char *ptr = arg + strlen (arg) - 1;
|
const char *ptr = arg + strlen (arg) - 1;
|
||||||
char *copy;
|
|
||||||
|
|
||||||
while (ptr >= arg && (*ptr == ' ' || *ptr == '\t'))
|
while (ptr >= arg && (*ptr == ' ' || *ptr == '\t'))
|
||||||
ptr--;
|
ptr--;
|
||||||
copy = xstrndup (arg, ptr + 1 - arg);
|
gdb::unique_xmalloc_ptr<char> copy
|
||||||
|
= make_unique_xstrndup (arg, ptr + 1 - arg);
|
||||||
|
|
||||||
val = tilde_expand (copy);
|
val = tilde_expand (copy.get ());
|
||||||
xfree (copy);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
val = xstrdup ("");
|
val = xstrdup ("");
|
||||||
|
@ -199,7 +199,8 @@ parser_state::mark_completion_tag (enum type_code tag, const char *ptr,
|
|||||||
|| tag == TYPE_CODE_STRUCT
|
|| tag == TYPE_CODE_STRUCT
|
||||||
|| tag == TYPE_CODE_ENUM);
|
|| tag == TYPE_CODE_ENUM);
|
||||||
m_completion_state.expout_tag_completion_type = tag;
|
m_completion_state.expout_tag_completion_type = tag;
|
||||||
m_completion_state.expout_completion_name.reset (xstrndup (ptr, length));
|
m_completion_state.expout_completion_name
|
||||||
|
= make_unique_xstrndup (ptr, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* See parser-defs.h. */
|
/* See parser-defs.h. */
|
||||||
|
@ -64,4 +64,13 @@ make_unique_xstrdup (const char *str)
|
|||||||
return gdb::unique_xmalloc_ptr<char> (xstrdup (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 */
|
#endif /* COMMON_GDB_UNIQUE_PTR_H */
|
||||||
|
Reference in New Issue
Block a user