From d8f925828cd1c9203aa96af8b72e15f6a8df422a Mon Sep 17 00:00:00 2001 From: Richard Frith-MacDonald Date: Mon, 31 Oct 2011 10:00:29 +0000 Subject: [PATCH] fix bug spotted by fred git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@34094 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 5 +++++ Source/GSString.m | 20 ++++++++++++++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3576f372d..aa866f460 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-10-28 Richard Frith-Macdonald + + * Source/GSString.m: Fix error (spotted by Fred) in check of UTF-8 + string length against fixed character size string length. + 2011-10-28 Richard Frith-Macdonald * Source/GSString.m: Implement more efficient equality tests for diff --git a/Source/GSString.m b/Source/GSString.m index 01e29b292..1d5f08e64 100644 --- a/Source/GSString.m +++ b/Source/GSString.m @@ -2352,6 +2352,14 @@ isEqual_c(GSStr self, id anObject) { NXConstantString *other = (NXConstantString*)anObject; + if (self->_count > other->nxcslen) + { + /* Since UTF-8 is a multibyte character set, it must have at least + * as many bytes as another string of the same length. So if the + * UTF-8 string is shorter, the two cannot be equal. + */ + return NO; + } if (internalEncoding == NSASCIIStringEncoding) { if (self->_count == other->nxcslen @@ -2452,6 +2460,14 @@ isEqual_u(GSStr self, id anObject) unsigned i = 0; unichar u; + if (self->_count > other->nxcslen) + { + /* Since UTF-8 is a multibyte character set, it must have at least + * as many bytes as another string of the same character length. + * So if the UTF-8 string is shorter, the two cannot be equal. + */ + return NO; + } while (i < other->nxcslen || n > 0) { u = nextUTF8((const uint8_t *)other->nxcsptr, other->nxcslen, &i, &n); @@ -5046,11 +5062,11 @@ literalIsEqual(NXConstantString *self, id anObject) unsigned i = 0; unichar u; - if (len < self->nxcslen) + if (len > self->nxcslen) { /* Since UTF-8 is a multibyte character set, it must have at least * as many bytes as another string of the same length. So if the - * other is shorter, the two cannot be equal. + * UTF-8 string is shorter, the two cannot be equal. */ return NO; }