path: root/enc
diff options
authorshyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-11-16 02:34:00 +0000
committershyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-11-16 02:34:00 +0000
commit6732423b5eb7191e81a23fe929926d50e0e4b39f (patch)
treef154be4a41e08925bad53c9958d0caca67457d61 /enc
parent3a083985a471ca3d8429146f9f18dead6747c203 (diff)
enc/unicode.c: 'a' is bigger than 'A'
In ASCII, 'a' is bigger than 'A'. Which means 'A' - 'a' is a negative number (-32, to be precise). In C, the type of 'a' and 'A' are signed int (cf: ISO/IEC 9899:1990 section So 'A' - 'a' is also a signed int. It is `(signed int)-32`. The problem is, OnigCodePoint is unsigned int. Adding a negative number to a variable of OnigCodepoint (`code` here) introduces an unintentional cast of `(unsigned)(signed)-32`, which is 4,294,967,264. Adding this value to code then overflows, and the result eventually becomes normal codepoint. The series of operations are not a serious problem but because `code >= 'a'` holds, we can `(code - 'a') + 'A'` to reroute this. See also: git-svn-id: svn+ssh:// b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'enc')
1 files changed, 4 insertions, 2 deletions
diff --git a/enc/unicode.c b/enc/unicode.c
index 0d69252..2c0d91d 100644
--- a/enc/unicode.c
+++ b/enc/unicode.c
@@ -683,8 +683,10 @@ onigenc_unicode_case_map(OnigCaseFoldType* flagP,
if (flags & ONIGENC_CASE_FOLD_TURKISH_AZERI && code == 'i')
- else
- code += 'A' - 'a';
+ else {
+ code -= 'a';
+ code += 'A';
+ }
else if (code >= 'A' && code <= 'Z') {