diff options
Diffstat (limited to 'cppe/src/IceE/ConvertUTF.cpp')
-rwxr-xr-x | cppe/src/IceE/ConvertUTF.cpp | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/cppe/src/IceE/ConvertUTF.cpp b/cppe/src/IceE/ConvertUTF.cpp index 2282028f10e..1cc28b25488 100755 --- a/cppe/src/IceE/ConvertUTF.cpp +++ b/cppe/src/IceE/ConvertUTF.cpp @@ -233,11 +233,25 @@ static Boolean isLegalUTF8(const UTF8 *source, int length) { * This is not used here; it's just exported.
*/
Boolean isLegalUTF8Sequence(const UTF8 *source, const UTF8 *sourceEnd) {
- int length = trailingBytesForUTF8[*source]+1;
- if (source+length > sourceEnd) {
- return false;
+ if(source == sourceEnd) {
+ return true;
+ }
+ while(true) {
+ int length = trailingBytesForUTF8[*source]+1;
+ // Is buffer big enough to contain character?
+ if (source+length > sourceEnd) {
+ return false;
+ }
+ // Is character legal UTF8?
+ if(!isLegalUTF8(source, length)) {
+ return false;
+ }
+ // Are we at end of buffer?
+ source += length;
+ if(source == sourceEnd) {
+ return true;
+ }
}
- return isLegalUTF8(source, length);
}
/* --------------------------------------------------------------------- */
|