diff --git a/Misc/NEWS b/Misc/NEWS index 819a401172b..ec857acde19 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -44,6 +44,11 @@ Library Extension Modules ----------------- +- Issue #9277: Fix bug in struct.pack for bools in standard mode + (e.g., struct.pack('>?')): if conversion to bool raised an exception + then that exception wasn't properly propagated on machines where + char is unsigned. + Build ----- diff --git a/Modules/_struct.c b/Modules/_struct.c index 52c5eeb1703..f22c31cd2a0 100644 --- a/Modules/_struct.c +++ b/Modules/_struct.c @@ -912,11 +912,11 @@ bp_double(char *p, PyObject *v, const formatdef *f) static int bp_bool(char *p, PyObject *v, const formatdef *f) { - char y; + int y; y = PyObject_IsTrue(v); if (y < 0) return -1; - memcpy(p, (char *)&y, sizeof y); + *p = (char)y; return 0; }