msg292836 - (view) |
Author: Xiang Zhang (xiang.zhang) *  |
Date: 2017-05-03 04:30 |
In struct there are several places using code like: p[--i] = (char)x; to extract the least significant byte from a long. Although this behaviour seems to apply to common implementations but it does not conform to C standard. |
|
|
msg292839 - (view) |
Author: Serhiy Storchaka (serhiy.storchaka) *  |
Date: 2017-05-03 05:06 |
I think it is better to change the type of p to unsigned char. |
|
|
msg292843 - (view) |
Author: Xiang Zhang (xiang.zhang) *  |
Date: 2017-05-03 05:52 |
> I think it is better to change the type of p to unsigned char. Good advice. |
|
|
msg292844 - (view) |
Author: Serhiy Storchaka (serhiy.storchaka) *  |
Date: 2017-05-03 06:20 |
I meant changing the type of the first argument of np_ubyte() etc. np_ubyte(unsigned char *p, PyObject *v, const formatdef *f) |
|
|
msg292845 - (view) |
Author: Xiang Zhang (xiang.zhang) *  |
Date: 2017-05-03 06:25 |
Hmm, do we need to? Currently all pack routines accept a char *p. Converting it to unsigned char * inside could also solve the problem. |
|
|
msg292847 - (view) |
Author: Serhiy Storchaka (serhiy.storchaka) *  |
Date: 2017-05-03 07:03 |
Your patch LGTM as a minimal patch for backporting to maintained releases (maybe Mark have other comments). But I think it would be better to make all pointers to raw memory of type unsigned char*. Not just packing, but unpacking too. Using even memcpy between long* and char* is undefined behavior, the source and target should either have the same type, or one of them be unsigned char*. |
|
|
msg293670 - (view) |
Author: Xiang Zhang (xiang.zhang) *  |
Date: 2017-05-15 04:04 |
New changeset 981096f98b9c131594b0ac85ad01b63cbd11aa0a by Xiang Zhang in branch 'master': bpo-30242: resolve some undefined behaviours in struct (#1418) https://github.com/python/cpython/commit/981096f98b9c131594b0ac85ad01b63cbd11aa0a |
|
|
msg293674 - (view) |
Author: Xiang Zhang (xiang.zhang) *  |
Date: 2017-05-15 05:17 |
New changeset aad1caf55f7fadb00ee097a1465bece4e128d8ef by Xiang Zhang in branch '3.6': bpo-30242: resolve some undefined behaviours in struct (#1418) (#1586) https://github.com/python/cpython/commit/aad1caf55f7fadb00ee097a1465bece4e128d8ef |
|
|
msg293675 - (view) |
Author: Xiang Zhang (xiang.zhang) *  |
Date: 2017-05-15 05:17 |
New changeset dd2a09cf98845b1460f0e049ad0ffeeb5c6c6476 by Xiang Zhang in branch '3.5': bpo-30242: resolve some undefined behaviours in struct (#1418) (#1587) https://github.com/python/cpython/commit/dd2a09cf98845b1460f0e049ad0ffeeb5c6c6476 |
|
|
msg293676 - (view) |
Author: Xiang Zhang (xiang.zhang) *  |
Date: 2017-05-15 05:17 |
New changeset 982a17e02d99dcf6e4dff93110cff5ecc59247f5 by Xiang Zhang in branch '2.7': bpo-30242: resolve some undefined behaviours in struct (#1418) (#1588) https://github.com/python/cpython/commit/982a17e02d99dcf6e4dff93110cff5ecc59247f5 |
|
|