Commit 5f45979b authored by Alexey Izbyshev's avatar Alexey Izbyshev Committed by Inada Naoki

bpo-35194: cjkcodec: check the encoded value is not truncated (GH-10432)

parent 9e30fbac
...@@ -149,40 +149,42 @@ static const struct dbcs_map *mapping_list; ...@@ -149,40 +149,42 @@ static const struct dbcs_map *mapping_list;
writer->pos += 2; \ writer->pos += 2; \
} while (0) } while (0)
#define OUTBYTE1(c) \ #define OUTBYTEI(c, i) \
do { ((*outbuf)[0]) = (c); } while (0) do { \
#define OUTBYTE2(c) \ assert((unsigned char)(c) == (c)); \
do { ((*outbuf)[1]) = (c); } while (0) ((*outbuf)[i]) = (c); \
#define OUTBYTE3(c) \ } while (0)
do { ((*outbuf)[2]) = (c); } while (0)
#define OUTBYTE4(c) \ #define OUTBYTE1(c) OUTBYTEI(c, 0)
do { ((*outbuf)[3]) = (c); } while (0) #define OUTBYTE2(c) OUTBYTEI(c, 1)
#define OUTBYTE3(c) OUTBYTEI(c, 2)
#define OUTBYTE4(c) OUTBYTEI(c, 3)
#define WRITEBYTE1(c1) \ #define WRITEBYTE1(c1) \
do { \ do { \
REQUIRE_OUTBUF(1); \ REQUIRE_OUTBUF(1); \
(*outbuf)[0] = (c1); \ OUTBYTE1(c1); \
} while (0) } while (0)
#define WRITEBYTE2(c1, c2) \ #define WRITEBYTE2(c1, c2) \
do { \ do { \
REQUIRE_OUTBUF(2); \ REQUIRE_OUTBUF(2); \
(*outbuf)[0] = (c1); \ OUTBYTE1(c1); \
(*outbuf)[1] = (c2); \ OUTBYTE2(c2); \
} while (0) } while (0)
#define WRITEBYTE3(c1, c2, c3) \ #define WRITEBYTE3(c1, c2, c3) \
do { \ do { \
REQUIRE_OUTBUF(3); \ REQUIRE_OUTBUF(3); \
(*outbuf)[0] = (c1); \ OUTBYTE1(c1); \
(*outbuf)[1] = (c2); \ OUTBYTE2(c2); \
(*outbuf)[2] = (c3); \ OUTBYTE3(c3); \
} while (0) } while (0)
#define WRITEBYTE4(c1, c2, c3, c4) \ #define WRITEBYTE4(c1, c2, c3, c4) \
do { \ do { \
REQUIRE_OUTBUF(4); \ REQUIRE_OUTBUF(4); \
(*outbuf)[0] = (c1); \ OUTBYTE1(c1); \
(*outbuf)[1] = (c2); \ OUTBYTE2(c2); \
(*outbuf)[2] = (c3); \ OUTBYTE3(c3); \
(*outbuf)[3] = (c4); \ OUTBYTE4(c4); \
} while (0) } while (0)
#define _TRYMAP_ENC(m, assi, val) \ #define _TRYMAP_ENC(m, assi, val) \
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment