fix for issue #365

This commit is contained in:
rfm 2024-01-29 14:27:32 +00:00
parent 75fd9549ef
commit b7f66a9dd3
2 changed files with 32 additions and 12 deletions

View file

@ -1,5 +1,9 @@
2024-01-08 Richard Frith-Macdonald <rfm@gnu.org>
* Source/NSJSONSerialization.m: Fix for issue #365 ... don't try to
create a string ending with the first half of a unicode surrogate pair.
2024-01-08 Richard Frith-Macdonald <rfm@gnu.org>
* Source/NSNotificationCenter.m: fix for memory leak should keep the
observer retained until removed.

View file

@ -413,20 +413,36 @@ parseString(ParserState *state)
buffer[bufferIndex++] = next;
if (bufferIndex >= BUFFER_SIZE)
{
NSMutableString *str;
NSMutableString *str;
int len = bufferIndex;
str = [[NSMutableString alloc] initWithCharacters: buffer
length: bufferIndex];
bufferIndex = 0;
if (nil == val)
{
val = str;
}
else
{
[val appendString: str];
[str release];
}
if (next < 0xd800 || next > 0xdbff)
{
str = [[NSMutableString alloc] initWithCharacters: buffer
length: len];
}
else
{
/* The most recent unicode character is the first half of a
* surrogate pair, so we need to defer it to the next chunk
* to make sure the whole unicode character is in the same
* string (otherwise we would have an invalid string).
*/
len--;
str = [[NSMutableString alloc] initWithCharacters: buffer
length: len];
buffer[bufferIndex++] = next;
}
if (nil == val)
{
val = str;
}
else
{
[val appendString: str];
RELEASE(str);
}
}
next = consumeChar(state);
}