aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Tatham <anakin@pobox.com>2012-06-06 17:59:37 +0000
committerSimon Tatham <anakin@pobox.com>2012-06-06 17:59:37 +0000
commit48e9767a206420294147f802a8a2cc5c9e77141c (patch)
tree8706d0999bb59d520970d0eb89c1e24784989c23
parent5a095b8a08fa9f087b93c86aea0fa027138b028d (diff)
downloadpuzzles-48e9767a206420294147f802a8a2cc5c9e77141c.zip
puzzles-48e9767a206420294147f802a8a2cc5c9e77141c.tar.gz
puzzles-48e9767a206420294147f802a8a2cc5c9e77141c.tar.bz2
puzzles-48e9767a206420294147f802a8a2cc5c9e77141c.tar.xz
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]
-rw-r--r--osx.m11
1 files changed, 6 insertions, 5 deletions
diff --git a/osx.m b/osx.m
index b59999d..6e709a5 100644
--- a/osx.m
+++ b/osx.m
@@ -1088,15 +1088,16 @@ struct frontend {
p = i->sval;
c = *p++;
while (*p) {
- char cc, *q;
+ char *q, *copy;
q = p;
while (*p && *p != c) p++;
- cc = *p;
- *p = '\0';
- [pb addItemWithTitle:[NSString stringWithUTF8String:q]];
- *p = cc;
+ copy = snewn((p-q) + 1, char);
+ memcpy(copy, q, p-q);
+ copy[p-q] = '\0';
+ [pb addItemWithTitle:[NSString stringWithUTF8String:copy]];
+ sfree(copy);
if (*p) p++;
}