Skip to content
This repository has been archived by the owner on Jun 3, 2024. It is now read-only.

raw buffer initialization of bool has guaranteed UB because of va_args usage in generated code #45

Open
lefticus opened this issue Mar 10, 2024 · 0 comments

Comments

@lefticus
Copy link
Collaborator

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.
@lefticus lefticus changed the title raw buffer of bool has guaranteed UB because of va_args usage in generated code raw buffer initialization of bool has guaranteed UB because of va_args usage in generated code Mar 10, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant