Fix a serious misunderstanding of the icu string access API: The value

of nativeIndexingLimit must not exceed the length of the current chunk.


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@40333 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
wlux 2017-02-11 14:24:58 +00:00
parent 176f96a061
commit fe35571c9b
4 changed files with 24 additions and 3 deletions

View file

@ -1,3 +1,13 @@
2017-02-11 Wolfgang Lux <wolfgang.lux@gmail.com>
* Source/GSICUString.m (UTextNSStringAccess,
UTextInitWithNSMutableString, UTextInitWithNSString):
Fix a serious misunderstanding of the icu string access API: The
value of nativeIndexingLimit must not exceed the length of the
current chunk. Otherwise icu library macros could miss to properly
reinitialize chunks, which, for instance, could lead to returning
regular expression matches outside the selected range.
2017-01-06 Richard Frith-Macdonald <rfm@gnu.org>
* Tools/gdomap.c: Use getaddrinfo rather than gethostbyname if

View file

@ -130,6 +130,7 @@ UTextNSStringAccess(UText *ut, int64_t nativeIndex, UBool forward)
[str getCharacters: ut->pExtra range: r];
ut->chunkNativeLimit = nativeLimit;
ut->chunkNativeStart = nativeStart;
ut->nativeIndexingLimit = r.length;
ut->chunkLength = r.length;
return TRUE;
}
@ -378,7 +379,6 @@ UTextInitWithNSMutableString(UText *txt, NSMutableString *str)
txt->p = [str retain];
txt->pFuncs = &NSMutableStringFuncs;
txt->chunkContents = txt->pExtra;
txt->nativeIndexingLimit = INT32_MAX;
txt->c = -1; // Need to fetch length every time
txt->providerProperties = 1<<UTEXT_PROVIDER_WRITABLE;
@ -399,7 +399,6 @@ UTextInitWithNSString(UText *txt, NSString *str)
txt->p = [str retain];
txt->pFuncs = &NSStringFuncs;
txt->chunkContents = txt->pExtra;
txt->nativeIndexingLimit = INT32_MAX;
txt->c = [str length];
return txt;

View file

@ -31,7 +31,7 @@
/* FIXME It would be nice to use autoconf for checking whether uregex_openUText
* is defined. However the naive check using AC_CHECK_FUNCS(uregex_openUText)
* wonn't work because libicu internally renames all entry points with some cpp
* won't work because libicu internally renames all entry points with some cpp
* magic.
*/
#if (U_ICU_VERSION_MAJOR_NUM > 4 || (U_ICU_VERSION_MAJOR_NUM == 4 && U_ICU_VERSION_MINOR_NUM >= 4))

View file

@ -2,6 +2,7 @@
#import "ObjectTesting.h"
#import <Foundation/NSAutoreleasePool.h>
#import <Foundation/NSRegularExpression.h>
#import <Foundation/NSTextCheckingResult.h>
#import <Foundation/NSDate.h>
#import <Foundation/NSDictionary.h>
#import <Foundation/NSUserDefaults.h>
@ -129,6 +130,17 @@ int main()
template: @"c"];
PASS_EQUAL(replacement, @"c",
"Custom replacement: Returns correct replacement");
NSRegularExpression *testObj2 =
[[NSRegularExpression alloc] initWithPattern: @"bc"
options: 0
error: NULL];
r = [testObj2 firstMatchInString: @"abcdeabcde"
options: 0
range: NSMakeRange(5, 5)];
PASS(r != nil && NSEqualRanges([r range], NSMakeRange(6, 2)),
"Restricting the range for firstMatchInString: works");
/* To test whether we correctly bail out of processing degenerate patterns,
* we spin up a new thread and evaluate an expression there. The expectation
* is that the thread should terminate within a few seconds.