Our version of _CTASSERT does not work as static assert.
$ uname -a
NetBSD rugged 8.99.42 NetBSD 8.99.42 (GENERIC) #2: Sat Jun  1 22:52:15
CEST 2019
root@chieftec:/public/netbsd-root/sys/arch/amd64/compile/GENERIC amd64
$ cat test.c
#include <sys/cdefs.h>
int main(int argc, char **argv) { __CTASSERT(argc < 0); return 0; }
$ gcc test.c
$ ./a.out
$
This actually rendered into a bug caught by kUBSan:
[   1.0000000] panic: UBSan: Undefined Behavior in
/syzkaller/managers/netbsd-kubsan/kernel/sys/crypto/nist_hash_drbg/nist_hash_drbg.c:1090:4,
variable length array bound value -1 <= 0
-- https://syzkaller.appspot.com/x/log.txt?x=1524c2ad600000
I propose the following version to enforce constantness using bit-fields.
http://netbsd.org/~kamil/patch-00150-__CTASSERT1-bitfield.txt
Prior-art is in Perl:
https://perl5.git.perl.org/perl.git/blob/44523d1ffde5f23de2e13216cdbac46357631904:/perl.h#l3455
BTW. This will break building in a few places where __CTASSERT is
misused in a similar way.
Attachment:
signature.asc
Description: OpenPGP digital signature