From 31e5ad789a51be34fe4fb8c7f18bd8f36c6c28c0 Mon Sep 17 00:00:00 2001 From: Michael Matz Date: Sat, 27 May 2017 22:44:53 +0200 Subject: [PATCH] Limit access end-of-struct warning a bit Only warn if the struct has a non-zero size. You can't create objects of zero-sized structs, but they can be used inside sizeof (e.g. "sizeof (struct {int :0;})". The warning would always trigger for these, but as no objects can be created no accesses can ever happen. --- tccgen.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tccgen.c b/tccgen.c index 9eb29f6e..1a8ba3d7 100644 --- a/tccgen.c +++ b/tccgen.c @@ -3471,7 +3471,7 @@ static void struct_layout(CType *type, AttributeDef *ad) type->ref->c = (c + (pcc ? (bit_pos + 7) >> 3 : 0) + maxalign - 1) & -maxalign; type->ref->r = maxalign; - if (offset + size > type->ref->c) + if (offset + size > type->ref->c && type->ref->c) tcc_warning("will touch memory past end of the struct (internal limitation)"); } -- 2.11.4.GIT