Bug 30404 - Incorrect evaluation of sizeof(*pointer) for structure with zero length array
Summary: Incorrect evaluation of sizeof(*pointer) for structure with zero length array
Status: UNCONFIRMED
Alias: None
Product: gdb
Classification: Unclassified
Component: exp (show other bugs)
Version: 12.1
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-04-29 11:19 UTC by Marc Butler
Modified: 2023-04-29 11:19 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments
Use with gdb to demonstrate bug. (182 bytes, text/plain)
2023-04-29 11:19 UTC, Marc Butler
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Marc Butler 2023-04-29 11:19:54 UTC
Created attachment 14856 [details]
Use with gdb to demonstrate bug.

When the last element of a C language struct is a zero length array, the evaluation of sizeof(*(struct S*)pointer) does not match sizeof(struct S).

> Breakpoint 1, fn (ps=0x7fffffffe250) at demo-sizeof-bug.c:15
> 15              printf("ps = %p\n", ps);
> (gdb) p sizeof(*ps)
> $1 = 7
> (gdb) p sizeof(struct S)
> $2 = 8
> (gdb) ptype/o *ps
> /* offset      |    size */  type = struct S {
> /*      0      |       4 */    int32_t f1;
> /*      4      |       2 */    int16_t f2;
> /*      6      |       1 */    int8_t f3;
> /*      7      |       0 */    int8_t f4[];
>                              /* total size (bytes):    7 */