bpo-35194: cjkcodec: check the encoded value is not truncated#10432
bpo-35194: cjkcodec: check the encoded value is not truncated#10432methane merged 2 commits intopython:masterfrom
Conversation
| do { ((*outbuf)[2]) = (c); } while (0) | ||
| #define OUTBYTE4(c) \ | ||
| do { ((*outbuf)[3]) = (c); } while (0) | ||
| #define OUTBYTEI(c, i) \ |
There was a problem hiding this comment.
Can you try to convert this macro to a static inline function? I'm trying to slowly convert macros to static inline functions. It avoids uglyness of macros like do { ... } while (0). See https://bugs.python.org/issue35059
For example, a function would require a specific type for c :-) Maybe DBCHAR type?
There was a problem hiding this comment.
The advantage of macros for the purpose of catching conversions changing the mathematical value is that (unsigned char)(c) == (c) checks it for any integer type of c. Note that mathematical values of both operands are never changed in this comparison, at least if we consider C99-conforming compilers and don't take into account platforms where a byte is not 8-bit.
If we used a function instead, c would always be converted to its parameter type. No matter what type we choose, even the widest one, the mathematical value of the argument can be changed (if not because of truncation, than because of conversions between signed and unsigned types). So I don't see how static inline functions can help in this particular issue. Macros may be ugly, but they may also be a powerful tool for specific tasks.
https://bugs.python.org/issue35194