Fix a bug introduced by r9495 in which we try to write temporary NULs

into a string which is usually a read-only string literal. Instead,
copy each segment into writable memory as we need it, and free it
afterwards.

[originally from svn r9558]
[r9495 == d0ff371b144d4bfe3cbfb062388347c08e431393]
This commit is contained in:
Simon Tatham
2012-06-06 17:59:37 +00:00
parent 5a095b8a08
commit 48e9767a20

11
osx.m
View File

@ -1088,15 +1088,16 @@ struct frontend {
p = i->sval; p = i->sval;
c = *p++; c = *p++;
while (*p) { while (*p) {
char cc, *q; char *q, *copy;
q = p; q = p;
while (*p && *p != c) p++; while (*p && *p != c) p++;
cc = *p; copy = snewn((p-q) + 1, char);
*p = '\0'; memcpy(copy, q, p-q);
[pb addItemWithTitle:[NSString stringWithUTF8String:q]]; copy[p-q] = '\0';
*p = cc; [pb addItemWithTitle:[NSString stringWithUTF8String:copy]];
sfree(copy);
if (*p) p++; if (*p) p++;
} }