diff options
author | Alex Beregszaszi <alex@rtfs.hu> | 2017-06-17 00:23:11 +0800 |
---|---|---|
committer | Alex Beregszaszi <alex@rtfs.hu> | 2017-06-26 19:58:22 +0800 |
commit | 6488f7e0795a77e4175361e3cb7270b47168a22a (patch) | |
tree | a2c9fadb347414cfb7e80c4823f89de0fbf8c2b4 /libdevcore/UTF8.cpp | |
parent | 569e0c53f276eccbd9452988910aa8f3b4bcf13f (diff) | |
download | dexon-solidity-6488f7e0795a77e4175361e3cb7270b47168a22a.tar.gz dexon-solidity-6488f7e0795a77e4175361e3cb7270b47168a22a.tar.zst dexon-solidity-6488f7e0795a77e4175361e3cb7270b47168a22a.zip |
Validate first byte properly for UTF8
Diffstat (limited to 'libdevcore/UTF8.cpp')
-rw-r--r-- | libdevcore/UTF8.cpp | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/libdevcore/UTF8.cpp b/libdevcore/UTF8.cpp index 793bc080..ad62c8b0 100644 --- a/libdevcore/UTF8.cpp +++ b/libdevcore/UTF8.cpp @@ -85,11 +85,19 @@ bool validateUTF8(std::string const& _input, size_t& _invalidPosition) continue; size_t count = 0; - switch(_input[i] & 0xf0) { - case 0xc0: count = 1; break; - case 0xe0: count = 2; break; - case 0xf0: count = 3; break; - default: break; + switch ((unsigned char)_input[i]) + { + case 0xc0 ... 0xdf: + count = 1; + break; + case 0xe0 ... 0xef: + count = 2; + break; + case 0xf0 ... 0xf7: + count = 3; + break; + default: + break; } if (count == 0) |