This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
utf8.h: Add assertions to macro
authorKarl Williamson <khw@cpan.org>
Fri, 15 May 2015 16:55:30 +0000 (10:55 -0600)
committerKarl Williamson <khw@cpan.org>
Fri, 4 Sep 2015 16:21:17 +0000 (10:21 -0600)
utf8.h

diff --git a/utf8.h b/utf8.h
index 2e1aa02..271796b 100644 (file)
--- a/utf8.h
+++ b/utf8.h
@@ -356,8 +356,10 @@ encoded as UTF-8.  C<cp> is a native (ASCII or EBCDIC) code point if less than
  * Note that the result can be larger than 255 if the input character is not
  * downgradable */
 #define TWO_BYTE_UTF8_TO_NATIVE(HI, LO) \
  * Note that the result can be larger than 255 if the input character is not
  * downgradable */
 #define TWO_BYTE_UTF8_TO_NATIVE(HI, LO) \
+    ( __ASSERT_(UTF8SKIP(HI) == 2)                                              \
+      __ASSERT_(UTF8_IS_CONTINUATION(LO))                                       \
      UNI_TO_NATIVE(UTF8_ACCUMULATE((NATIVE_UTF8_TO_I8(HI) & UTF_START_MASK(2)), \
      UNI_TO_NATIVE(UTF8_ACCUMULATE((NATIVE_UTF8_TO_I8(HI) & UTF_START_MASK(2)), \
-                                   (LO)))
+                                   (LO))))
 
 /* Should never be used, and be deprecated */
 #define TWO_BYTE_UTF8_TO_UNI(HI, LO) NATIVE_TO_UNI(TWO_BYTE_UTF8_TO_NATIVE(HI, LO))
 
 /* Should never be used, and be deprecated */
 #define TWO_BYTE_UTF8_TO_UNI(HI, LO) NATIVE_TO_UNI(TWO_BYTE_UTF8_TO_NATIVE(HI, LO))