june
june copied to clipboard
raw buffer initialization of `bool` has guaranteed UB because of va_args usage in generated code
I believe you are getting a 4 byte write (default int
, 32bits on all modern platforms) for each 1 byte bool
object.
Input
mut blob = raw[true, false]
Output from GCC (with no compiler warnings enabled)
build/debug/main.c: In function ‘create_buffer_11’:
build/debug/main.c:402:17: warning: ‘_Bool’ is promoted to ‘int’ when passed through ‘...’
402 | *(output + i) = va_arg(args, bool);
| ^~~~~~
build/debug/main.c:402:17: note: (so you should pass ‘int’ not ‘_Bool’ to ‘va_arg’)
build/debug/main.c:402:17: note: if this code is reached, the program will abort
Output from clang:
*(output + i) = va_arg(args, bool);
^~~~
/usr/lib/clang/16/include/stdbool.h:20:14: note: expanded from macro 'bool'
#define bool _Bool
^~~~~
/usr/lib/clang/16/include/stdarg.h:36:50: note: expanded from macro 'va_arg'
#define va_arg(ap, type) __builtin_va_arg(ap, type)
^~~~
1 warning generated.