From 0447e8df3db3f566f76a613f62c5f4cdd7262997 Mon Sep 17 00:00:00 2001 From: Karl Williamson Date: Wed, 18 Apr 2012 15:25:28 -0600 Subject: [PATCH] utf8.h: Use correct definition of start byte The previous definition allowed for (illegal) overlongs. The uses of this macro in the core assume that it is accurate. The inacurracy can cause such code to fail. --- utf8.h | 4 +--- utfebcdic.h | 3 ++- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/utf8.h b/utf8.h index 152a937..06418d6 100644 --- a/utf8.h +++ b/utf8.h @@ -139,9 +139,7 @@ Perl's extended UTF-8 means we can have start bytes up to FF. */ #define UNI_IS_INVARIANT(c) (((UV)c) < 0x80) -/* Note that C0 and C1 are invalid in legal UTF8, so the lower bound of the - * below might ought to be C2 */ -#define UTF8_IS_START(c) (((U8)c) >= 0xc0) +#define UTF8_IS_START(c) (((U8)c) >= 0xc2) #define UTF8_IS_CONTINUATION(c) (((U8)c) >= 0x80 && (((U8)c) <= 0xbf)) #define UTF8_IS_CONTINUED(c) (((U8)c) & 0x80) diff --git a/utfebcdic.h b/utfebcdic.h index b3b767d..eff444e 100644 --- a/utfebcdic.h +++ b/utfebcdic.h @@ -584,7 +584,8 @@ END_EXTERN_C #define UNI_IS_INVARIANT(c) ((c) < 0xA0) /* UTF-EBCDIC semantic macros - transform back into I8 and then compare */ -#define UTF8_IS_START(c) (NATIVE_TO_UTF(c) >= 0xA0 && (NATIVE_TO_UTF(c) & 0xE0) != 0xA0) + +#define UTF8_IS_START(c) (NATIVE_TO_UTF(c) >= 0xC5 && NATIVE_TO_UTF(c) != 0xE0) #define UTF8_IS_CONTINUATION(c) ((NATIVE_TO_UTF(c) & 0xE0) == 0xA0) #define UTF8_IS_CONTINUED(c) (NATIVE_TO_UTF(c) >= 0xA0) #define UTF8_IS_DOWNGRADEABLE_START(c) (NATIVE_TO_UTF(c) >= 0xC5 && NATIVE_TO_UTF(c) <= 0xC7) -- 1.8.3.1