Fix bound checking for packed struct

This commit is contained in:
herman ten brugge 2020-08-11 07:33:11 +02:00
parent 09ed7e9557
commit 8b8e714517
2 changed files with 17 additions and 0 deletions

View File

@ -1871,9 +1871,15 @@ ST_FUNC void gaddrof(void)
/* generate a bounded pointer addition */
static void gen_bounded_ptr_add(void)
{
int save = (vtop[-1].r & VT_VALMASK) == VT_LOCAL;
if (save) {
vpushv(&vtop[-1]);
vrott(3);
}
vpush_global_sym(&func_old_type, TOK___bound_ptr_add);
vrott(3);
gfunc_call(2);
vtop -= save;
vpushi(0);
/* returned pointer is in REG_IRET */
vtop->r = REG_IRET | VT_BOUNDED;

View File

@ -129,6 +129,16 @@ void tst_compare(void)
if (tst() > 0) printf ("error\n");
}
#pragma pack(1)
struct S { int d:24; int f:14; } i, j;
#pragma pack()
void tst_pack (void)
{
i.f = 5; j.f = 5;
if (j.f != i.f) printf("error\n");
}
int
main (void)
{
@ -144,4 +154,5 @@ main (void)
tst_adr(&sprintf);
tst_builtin();
tst_compare();
tst_pack();
}