Skip to content

Commit

Permalink
types: fix nested structure typedefs format (#4614)
Browse files Browse the repository at this point in the history
  • Loading branch information
XVilka authored Sep 5, 2024
1 parent 1f78e11 commit 5830679
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
6 changes: 5 additions & 1 deletion librz/type/format.c
Original file line number Diff line number Diff line change
Expand Up @@ -2850,7 +2850,11 @@ static void base_type_to_format_no_unfold(const RzTypeDB *typedb, RZ_NONNULL RzB
char *fmt = rz_type_as_format(typedb, type->type);
if (fmt) {
rz_strbuf_append(format, fmt);
rz_strbuf_appendf(fields, "%s ", identifier);
if (!rz_type_is_atomic(typedb, type->type)) {
rz_strbuf_appendf(fields, "(%s)%s ", type->name, identifier);
} else {
rz_strbuf_appendf(fields, "%s ", identifier);
}
} else {
type_to_format_pair(typedb, format, fields, identifier, type->type);
}
Expand Down
22 changes: 22 additions & 0 deletions test/db/cmd/types
Original file line number Diff line number Diff line change
Expand Up @@ -8303,3 +8303,25 @@ EXPECT=<<EOF
4 fd: 6 +0x00000d98 0x00200d98 - 0x0020100f r-- vmap.LOAD1
EOF
RUN

NAME=tp nested structs with typedefs
FILE=--
CMDS=<<EOF
e asm.arch=arm
e asm.bits=64
td "typedef struct { int a; char b; struct { float c; char d[5]; } q; long long *z; } bla_t"
td "typedef struct { char a; unsigned b; long long *z; } moo_t"
td "typedef struct { void *a; char b[10]; struct { double c; char d[5]; } q;} goo_t"
td "typedef struct { bla_t bla[2]; moo_t moot; goo_t goot; } bmg"
tl bmg;
tl bla_t;
tl moo_t;
tl goo_t;
EOF
EXPECT=<<EOF
typedef bmg (0x2a0) "[2]??? (bla_t)bla (moo_t)moot (goo_t)goot"
typedef bla_t (0xb0) "dc?*q a b (anonymous struct 1)q z"
typedef moo_t (0x48) "c*q a z"
typedef goo_t (0xf8) "p[10]c? a b (anonymous struct 4)q"
EOF
RUN

0 comments on commit 5830679

Please sign in to comment.