Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions Modules/_struct.c
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ np_ubyte(char *p, PyObject *v, const formatdef *f)
"ubyte format requires 0 <= number <= 255");
return -1;
}
*p = (char)x;
*(unsigned char *)p = (unsigned char)x;
return 0;
}

Expand Down Expand Up @@ -814,6 +814,7 @@ bp_int(char *p, PyObject *v, const formatdef *f)
{
long x;
Py_ssize_t i;
unsigned char *q = (unsigned char *)p;
if (get_long(v, &x) < 0)
return -1;
i = f->size;
Expand All @@ -826,7 +827,7 @@ bp_int(char *p, PyObject *v, const formatdef *f)
#endif
}
do {
p[--i] = (char)x;
q[--i] = (unsigned char)(x & 0xffL);
x >>= 8;
} while (i > 0);
return 0;
Expand All @@ -837,6 +838,7 @@ bp_uint(char *p, PyObject *v, const formatdef *f)
{
unsigned long x;
Py_ssize_t i;
unsigned char *q = (unsigned char *)p;
if (get_ulong(v, &x) < 0)
return -1;
i = f->size;
Expand All @@ -847,7 +849,7 @@ bp_uint(char *p, PyObject *v, const formatdef *f)
return _range_error(f, 1);
}
do {
p[--i] = (char)x;
q[--i] = (unsigned char)(x & 0xffUL);
x >>= 8;
} while (i > 0);
return 0;
Expand Down Expand Up @@ -1034,6 +1036,7 @@ lp_int(char *p, PyObject *v, const formatdef *f)
{
long x;
Py_ssize_t i;
unsigned char *q = (unsigned char *)p;
if (get_long(v, &x) < 0)
return -1;
i = f->size;
Expand All @@ -1046,7 +1049,7 @@ lp_int(char *p, PyObject *v, const formatdef *f)
#endif
}
do {
*p++ = (char)x;
*q++ = (unsigned char)(x & 0xffL);
x >>= 8;
} while (--i > 0);
return 0;
Expand All @@ -1057,6 +1060,7 @@ lp_uint(char *p, PyObject *v, const formatdef *f)
{
unsigned long x;
Py_ssize_t i;
unsigned char *q = (unsigned char *)p;
if (get_ulong(v, &x) < 0)
return -1;
i = f->size;
Expand All @@ -1067,7 +1071,7 @@ lp_uint(char *p, PyObject *v, const formatdef *f)
return _range_error(f, 1);
}
do {
*p++ = (char)x;
*q++ = (unsigned char)(x & 0xffUL);
x >>= 8;
} while (--i > 0);
return 0;
Expand Down