https://git.alpinelinux.org/apk-tools/tree/src/adb.c?id=cef30b61c1a4c870f23f905423d76a287c22bf02#n478
(I need to figure out later if this code is actually correct.)
In 4f206ac1ea (Implement variable length arrays) arrays with the length 0
were considered to be variable length arrays. This may not be true and
caused cproc to segfault when parsing for example sizeof(int[0]). Using
t->prop & PROPVM as check for variable length arrays should always work
correctly.
Thanks for the patch!
However, the distinction between variably modified type and variably
length array is important here.
Consider this example:
#include <stdio.h>
int main(void) {
return sizeof(int (*[1])[(puts("fail"), 1)]) != sizeof(int *);
}
Here, the type is "array of length 1 of pointer to VLA of int".
This is an array type, and it is also a variably modified type since
there is a VLA in the derivation of the type, but it is not a VLA
itself.
Oh, well then maybe I don't understand cproc enought to fix this issue.
I have noticed some other issues too. Should I put them on todo.sr.ht or
the mailing list?
Have you found code like this in the wild?
Ideally we'd just fail on this earlier in decl.c:declarator() since
it's a constraint violation, but I suspect this would break a lot
of legacy code (predating C99 flexible array members) using zero-length
arrays in structs.
One idea might be to treat zero-length arrays as incomplete types.
This would make use with sizeof error out and also prevent declaring
variables with zero-length array type. The only problem is with
initialization, since then we'd be unable to distinguish
`int x[] = {1, 2, 3}` from the invalid `int x[0] = {1, 2, 3}`.