diff options
author | Oleg Nesterov <oleg@redhat.com> | 2020-02-12 11:04:14 +0100 |
---|---|---|
committer | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2020-02-13 18:32:38 +0100 |
commit | 9f207728de61eb503613dd960ff75aaa3fb73b36 (patch) | |
tree | d188b567c2d711c3b0d094724ccecb715f819ba7 | |
parent | c5e931373223bf2d16423f9740d5312a4d1900d1 (diff) | |
download | sparse-9f207728de61eb503613dd960ff75aaa3fb73b36.tar.gz |
dissect: don't set ->ident = '?' in no_member()
no_member() sets ->ident = built_in_ident("?") for the case when dissect()
can't figure out the name of initialized member. For example:
struct EMPTY {} var = { 10 };
the output:
1:25 var -w- m EMPTY.? bad type
This is useful, but dissect should not dictate the policy. Let r_member()
decide how this case should be reported.
Signed-off-by: Oleg Nesterov <oleg@redhat.com>
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
-rw-r--r-- | dissect.c | 6 | ||||
-rw-r--r-- | test-dissect.c | 7 |
2 files changed, 7 insertions, 6 deletions
@@ -123,11 +123,11 @@ static inline struct symbol *no_member(struct ident *name) { static struct symbol sym = { .type = SYM_BAD, + .ctype.base_type = &bad_ctype, .kind = 'm', }; - sym.ctype.base_type = &bad_ctype; - sym.ident = name ?: built_in_ident("?"); + sym.ident = name; return &sym; } @@ -137,7 +137,7 @@ static struct symbol *report_member(usage_t mode, struct position *pos, { struct symbol *ret = mem->ctype.base_type; - if (mem->ident) + if (mem->ident || mem->type == SYM_BAD) reporter->r_member(fix_mode(ret, mode), pos, type, mem); return ret; diff --git a/test-dissect.c b/test-dissect.c index 4b2d3bea..58b3e633 100644 --- a/test-dissect.c +++ b/test-dissect.c @@ -80,13 +80,14 @@ err: static void r_member(unsigned mode, struct position *pos, struct symbol *sym, struct symbol *mem) { - struct ident *si, *mi; + struct ident *ni, *si, *mi; print_usage(pos, sym, mode); - si = sym->ident ?: built_in_ident("?"); + ni = built_in_ident("?"); + si = sym->ident ?: ni; /* mem == NULL means entire struct accessed */ - mi = mem ? mem->ident : built_in_ident("*"); + mi = mem ? (mem->ident ?: ni) : built_in_ident("*"); printf("%c m %.*s.%-*.*s %s\n", symscope(sym), si->len, si->name, |