summaryrefslogtreecommitdiffstats
path: root/Modules/cjkcodecs
diff options
context:
space:
mode:
authorAlexey Izbyshev <izbyshev@ispras.ru>2019-03-29 07:48:47 (GMT)
committerInada Naoki <songofacandy@gmail.com>2019-03-29 07:48:47 (GMT)
commit5f45979b63300338b68709bfe817ddae563b93fd (patch)
tree6e8d7ff1c1b94de7f9d982fa44f70b0fce90536b /Modules/cjkcodecs
parent9e30fbac019d9c0a31d444a711e845c7e883caf5 (diff)
downloadcpython-5f45979b63300338b68709bfe817ddae563b93fd.zip
cpython-5f45979b63300338b68709bfe817ddae563b93fd.tar.gz
cpython-5f45979b63300338b68709bfe817ddae563b93fd.tar.bz2
bpo-35194: cjkcodec: check the encoded value is not truncated (GH-10432)
Diffstat (limited to 'Modules/cjkcodecs')
-rw-r--r--Modules/cjkcodecs/cjkcodecs.h38
1 files changed, 20 insertions, 18 deletions
diff --git a/Modules/cjkcodecs/cjkcodecs.h b/Modules/cjkcodecs/cjkcodecs.h
index 2ae28ec..b67f348 100644
--- a/Modules/cjkcodecs/cjkcodecs.h
+++ b/Modules/cjkcodecs/cjkcodecs.h
@@ -149,40 +149,42 @@ static const struct dbcs_map *mapping_list;
writer->pos += 2; \
} while (0)
-#define OUTBYTE1(c) \
- do { ((*outbuf)[0]) = (c); } while (0)
-#define OUTBYTE2(c) \
- do { ((*outbuf)[1]) = (c); } while (0)
-#define OUTBYTE3(c) \
- do { ((*outbuf)[2]) = (c); } while (0)
-#define OUTBYTE4(c) \
- do { ((*outbuf)[3]) = (c); } while (0)
+#define OUTBYTEI(c, i) \
+ do { \
+ assert((unsigned char)(c) == (c)); \
+ ((*outbuf)[i]) = (c); \
+ } while (0)
+
+#define OUTBYTE1(c) OUTBYTEI(c, 0)
+#define OUTBYTE2(c) OUTBYTEI(c, 1)
+#define OUTBYTE3(c) OUTBYTEI(c, 2)
+#define OUTBYTE4(c) OUTBYTEI(c, 3)
#define WRITEBYTE1(c1) \
do { \
REQUIRE_OUTBUF(1); \
- (*outbuf)[0] = (c1); \
+ OUTBYTE1(c1); \
} while (0)
#define WRITEBYTE2(c1, c2) \
do { \
REQUIRE_OUTBUF(2); \
- (*outbuf)[0] = (c1); \
- (*outbuf)[1] = (c2); \
+ OUTBYTE1(c1); \
+ OUTBYTE2(c2); \
} while (0)
#define WRITEBYTE3(c1, c2, c3) \
do { \
REQUIRE_OUTBUF(3); \
- (*outbuf)[0] = (c1); \
- (*outbuf)[1] = (c2); \
- (*outbuf)[2] = (c3); \
+ OUTBYTE1(c1); \
+ OUTBYTE2(c2); \
+ OUTBYTE3(c3); \
} while (0)
#define WRITEBYTE4(c1, c2, c3, c4) \
do { \
REQUIRE_OUTBUF(4); \
- (*outbuf)[0] = (c1); \
- (*outbuf)[1] = (c2); \
- (*outbuf)[2] = (c3); \
- (*outbuf)[3] = (c4); \
+ OUTBYTE1(c1); \
+ OUTBYTE2(c2); \
+ OUTBYTE3(c3); \
+ OUTBYTE4(c4); \
} while (0)
#define _TRYMAP_ENC(m, assi, val) \