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 <1583274310.32.0.931106124378.issue39689@roundup.psfhosted.org>
In-reply-to
Content
Using memcpy() to write a value different than 0 or 1 into a _Bool is clearly an undefined behavior. Example with clang UBSan.

bool.c:
---
#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'
History
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: <1583274310.32.0.931106124378.issue39689@roundup.psfhosted.org>
2020-03-03 22:25:10vstinnerlinkissue39689 messages
2020-03-03 22:25:10vstinnercreate