mirror of
https://github.com/dgibson/dtc.git
synced 2025-10-13 16:27:39 -04:00
Make build_property() xstrdup its name argument
The name field of 'struct property' was really always supposed to be a malloc()ed string, that is owned by the structure. To avoid an extra strdup() for strings coming up from the lexer, build_property() and build_property_delete() expect to take such an already malloc()ed string, which means it's not correct to pass it a static string literal. That's a pretty non-obvious constraint, so a bunch of incorrect uses have crept in. Really, avoiding the extra dup from the lexer isn't a big enough benefit for this demonstrably dangerous interface. So change it to do the xstrdup() itself, removing the burden from callers. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
This commit is contained in:
parent
9cceabea1e
commit
0b842c3c81
4 changed files with 10 additions and 7 deletions
|
@ -36,27 +36,27 @@ void delete_labels(struct label **labels)
|
|||
label->deleted = 1;
|
||||
}
|
||||
|
||||
struct property *build_property(char *name, struct data val,
|
||||
struct property *build_property(const char *name, struct data val,
|
||||
struct srcpos *srcpos)
|
||||
{
|
||||
struct property *new = xmalloc(sizeof(*new));
|
||||
|
||||
memset(new, 0, sizeof(*new));
|
||||
|
||||
new->name = name;
|
||||
new->name = xstrdup(name);
|
||||
new->val = val;
|
||||
new->srcpos = srcpos_copy(srcpos);
|
||||
|
||||
return new;
|
||||
}
|
||||
|
||||
struct property *build_property_delete(char *name)
|
||||
struct property *build_property_delete(const char *name)
|
||||
{
|
||||
struct property *new = xmalloc(sizeof(*new));
|
||||
|
||||
memset(new, 0, sizeof(*new));
|
||||
|
||||
new->name = name;
|
||||
new->name = xstrdup(name);
|
||||
new->deleted = 1;
|
||||
|
||||
return new;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue