From: simon Date: Wed, 6 Jun 2012 17:59:37 +0000 (+0000) Subject: Fix a bug introduced by r9495 in which we try to write temporary NULs X-Git-Url: https://git.distorted.org.uk/~mdw/sgt/puzzles/commitdiff_plain/9856b2637ad6d34dc05b6a4b41a0809db619537c 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. git-svn-id: svn://svn.tartarus.org/sgt/puzzles@9558 cda61777-01e9-0310-a592-d414129be87e --- 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++; }