libctf, create: fix ctf_type_add of structs with unnamed members
authorNick Alcock <nick.alcock@oracle.com>
Tue, 19 Jan 2021 12:45:18 +0000 (12:45 +0000)
committerNick Alcock <nick.alcock@oracle.com>
Tue, 19 Jan 2021 12:45:20 +0000 (12:45 +0000)
commit26503e2f5eae6019c8649a3dd204a82705efc740
tree8fc3af414a9e4af4fb532b64a8492a1ae434142a
parente05a3e5a491a8ef2079eef558bbe8e9feb0b3c03
libctf, create: fix ctf_type_add of structs with unnamed members

Our recent commit to support unnamed structure members better ditched
the old ctf_member_iter iterator body in favour of ctf_member_next.
However, these functions treat unnamed structure members differently:
ctf_member_iter just returned whatever the internal representation
contained, while ctf_member_next took care to always return "" rather
than sometimes returning "" and sometimes NULL depending on whether the
dict was dynamic (a product of ctf_create) or not (a product of
ctf_open).  After this commit, ctf_member_iter did the same.

It was always a bug for external callers not to treat a "" return from
these functions as if it were NULL, so only buggy callers could be
affected -- but one of those buggy callers was ctf_add_type, which
assumed that it could just take whatever name was returned from
ctf_member_iter and slam it directly into the internal representation of
a dynamic dict -- which expects NULL for unnamed members, not "".  The
net effect of all of this is that taking a struct containing unnamed
members and ctf_add_type'ing it into a dynamic dict produced a dict
whose unnamed members were inaccessible to ctf_member_info (though if
you wrote that dict out and then ctf_open'ed it, they would magically
reappear again).

Compensate for this by suitably transforming a "" name into NULL in the
internal representation, as should have been done all along.

libctf/ChangeLog
2021-01-19  Nick Alcock  <nick.alcock@oracle.com>

* ctf-create.c (membadd): Transform ""-named members into
NULL-named ones.
* testsuite/libctf-regression/type-add-unnamed-struct*: New test.
libctf/ChangeLog
libctf/ctf-create.c
libctf/testsuite/libctf-regression/type-add-unnamed-struct-ctf.c [new file with mode: 0644]
libctf/testsuite/libctf-regression/type-add-unnamed-struct.c [new file with mode: 0644]
libctf/testsuite/libctf-regression/type-add-unnamed-struct.lk [new file with mode: 0644]