Skip to content

Commit

Permalink
fix for issue #365
Browse files Browse the repository at this point in the history
  • Loading branch information
rfm committed Jan 29, 2024
1 parent 75fd954 commit b7f66a9
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 12 deletions.
4 changes: 4 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -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.

Expand Down
40 changes: 28 additions & 12 deletions Source/NSJSONSerialization.m
Original file line number Diff line number Diff line change
Expand Up @@ -413,20 +413,36 @@
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);
}
Expand Down

0 comments on commit b7f66a9

Please sign in to comment.