Author vstinner
Recipients ammar2, benjamin.peterson, cstratak, gregory.p.smith, mark.dickinson, meador.inge, petr.viktorin, vstinner
Date 2020-03-03.22:25:10
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
Using memcpy() to write a value different than 0 or 1 into a _Bool is clearly an undefined behavior. Example with clang UBSan.

#include <string.h>
#include <stdbool.h>

int main()
    char ch = 42;
    _Bool x;
    memcpy(&x, &ch, 1);
    return x == true;

$ clang -fsanitize=bool bool.c -o bool
$ ./bool
bool.c:9:12: runtime error: load of value 42, which is not a valid value for type '_Bool'
Date User Action Args
2020-03-03 22:25:10vstinnersetrecipients: + vstinner, gregory.p.smith, mark.dickinson, benjamin.peterson, petr.viktorin, meador.inge, cstratak, ammar2
2020-03-03 22:25:10vstinnersetmessageid: <>
2020-03-03 22:25:10vstinnerlinkissue39689 messages
2020-03-03 22:25:10vstinnercreate