@siguza@infosec.space
@jann@infosec.exchange I guess the correct thing would be max(offsetof(struct foo, arr[N]), sizeof(struct foo))? Which is really annoying, but that's just another name for C...
@jann@infosec.exchange I guess the correct thing would be max(offsetof(struct foo, arr[N]), sizeof(struct foo))? Which is really annoying, but that's just another name for C...
@siguza@infosec.space @jann@infosec.exchange unfortunately it's even worse if you're concerned with conformance, because the definition of offsetof states:
The type and member designator shall be such that given
static type t;
then the expression &(t.member-designator) evaluates to an address constant.
which completely rules out offsetof(foo, arr[N]) when N is not a compile-time constant, and admits only zero for a constant N.
@amonakov@mastodon.gamedev.place @siguza@infosec.space @jann@infosec.exchange (Found this by chance). I feel like I must be missing some context, because max(offsetof(struct foo, arr[0]), sizeof(struct foo)) doesn't return "0" for me?
https://godbolt.org/z/ror4KP3sc
@cr1901@mastodon.social @siguza@infosec.space @jann@infosec.exchange is that regarding the last sentence, "admits only zero for a constant N"? To rephrase, the text of the standard allows only zero in place of N in offsetof(foo, flexible_array_member[N]), not any other integer.
@amonakov@mastodon.gamedev.place @siguza@infosec.space @jann@infosec.exchange Yes, about that sentence. I didn't know that e.g. &foo.arr[3] doesn't evaluate to an address constant (feels like it should be allowed, unless the existence of that pointer runs afoul of the "one past the end" behavior).
But I'm not great w/ flexible array members anyway and mostly write C89 when I write C :P.
@cr1901@mastodon.social @amonakov@mastodon.gamedev.place @jann@infosec.exchange
unless the existence of that pointer runs afoul of the "one past the end" behaviorThat's precisely the issue.
max(offsetof(struct foo, arr[0]) + N * sizeof(((struct foo*)0)->arr[0]), sizeof(struct foo))