summaryrefslogtreecommitdiff
path: root/utfebcdic.h
diff options
context:
space:
mode:
authorKarl Williamson <khw@cpan.org>2015-08-26 15:35:05 -0600
committerKarl Williamson <khw@cpan.org>2015-09-04 10:49:22 -0600
commite9b19ab7df3480e8f710ca6faad519f6fccdb081 (patch)
treeab6c826ab4269c8fe118d11308f6af658bee1b0e /utfebcdic.h
parenta95ec4fb1da4ce753d2a8f3ecb2027679198a3a2 (diff)
downloadperl-e9b19ab7df3480e8f710ca6faad519f6fccdb081.tar.gz
utf8.h, utfebcdic.h: Add some assertions
These will detect a array bounds error that occurs on EBCDIC machines, and by including the assert on non-EBCDIC, we verify that the code wouldn't fail when built on EBCDIC.
Diffstat (limited to 'utfebcdic.h')
-rw-r--r--utfebcdic.h10
1 files changed, 6 insertions, 4 deletions
diff --git a/utfebcdic.h b/utfebcdic.h
index f490b586b1..51e6e77f8d 100644
--- a/utfebcdic.h
+++ b/utfebcdic.h
@@ -133,11 +133,13 @@ END_EXTERN_C
/* EBCDIC-happy ways of converting native code to UTF-8 */
-#define NATIVE_TO_LATIN1(ch) PL_e2a[(U8)(ch)]
-#define LATIN1_TO_NATIVE(ch) PL_a2e[(U8)(ch)]
+/* Use these when ch is known to be < 256 */
+#define NATIVE_TO_LATIN1(ch) (__ASSERT_(FITS_IN_8_BITS(ch)) PL_e2a[(U8)(ch)])
+#define LATIN1_TO_NATIVE(ch) (__ASSERT_(FITS_IN_8_BITS(ch)) PL_a2e[(U8)(ch)])
-#define NATIVE_UTF8_TO_I8(ch) PL_e2utf[(U8)(ch)]
-#define I8_TO_NATIVE_UTF8(ch) PL_utf2e[(U8)(ch)]
+/* Use these on bytes */
+#define NATIVE_UTF8_TO_I8(b) (__ASSERT_(FITS_IN_8_BITS(b)) PL_e2utf[(U8)(b)])
+#define I8_TO_NATIVE_UTF8(b) (__ASSERT_(FITS_IN_8_BITS(b)) PL_utf2e[(U8)(b)])
/* Transforms in wide UV chars */
#define NATIVE_TO_UNI(ch) (((ch) > 255) ? (ch) : NATIVE_TO_LATIN1(ch))