]> git.wh0rd.org Git - nano.git/commitdiff
Christian Weisgerber's fixes for answer corruption in files.c
authorChris Allegretta <chrisa@asty.org>
Sat, 26 Jun 2004 00:23:40 +0000 (00:23 +0000)
committerChris Allegretta <chrisa@asty.org>
Sat, 26 Jun 2004 00:23:40 +0000 (00:23 +0000)
git-svn-id: svn://svn.savannah.gnu.org/nano/branches/nano_1_2_branch/nano@1821 35c25a1d-7b9e-4130-9fde-d3aeb78583b8

ChangeLog
files.c
search.c

index 3ec9854a19bd96a81664728e3bbb0d708527b7af..a080b762eed36081f137fa19260ed347d1196dfc 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -9,6 +9,9 @@ CVS code -
          reading in a file (found by Mike Frysinger).
        - Port to the Tandem NonStop Kernel (nsr-tandem-nsk). (Tom
          Bates; minor tweaks by DLR)
+       - Fix memory corruption problems caused by assigning the
+         return value of statusq() to answer, since statusq() changes
+         the value that answer points to. (Christian Weisgerber)
 - nano.c:
   handle_sigwinch()
        - Rework so that nano properly redraws the screen on systems
diff --git a/files.c b/files.c
index 43fe0fb7d6efce38b44ec818b00bfe2ade01935a..90716a8e8232654b8ec56fda482aa84c4e5c7f1d 100644 (file)
--- a/files.c
+++ b/files.c
@@ -1721,16 +1721,17 @@ int do_writeout(const char *path, int exiting, int append)
 #ifdef NANO_EXTRA
     static int did_cred = 0;
 #endif
+    static char *writepath = NULL;
 
 #if !defined(DISABLE_BROWSER) || (!defined(DISABLE_MOUSE) && defined(NCURSES_MOUSE_VERSION))
     currshortcut = writefile_list;
 #endif
 
-    answer = mallocstrcpy(answer, path);
+    writepath = mallocstrcpy(writepath, path);
 
     if (exiting && ISSET(TEMP_OPT)) {
        if (filename[0] != '\0') {
-           i = write_file(answer, 0, 0, 0);
+           i = write_file(writepath, 0, 0, 0);
            display_main_list();
            return i;
        } else {
@@ -1771,24 +1772,24 @@ int do_writeout(const char *path, int exiting, int append)
                    "%s%s%s", _("Write Selection to File"), formatstr, backupstr);
        } else {
            if (append == 2)
-               i = statusq(1, writefile_list, answer, 0,
+               i = statusq(1, writefile_list, writepath, 0,
                    "%s%s%s", _("File Name to Prepend to"), formatstr, backupstr);
            else if (append == 1)
-               i = statusq(1, writefile_list, answer, 0,
+               i = statusq(1, writefile_list, writepath, 0,
                    "%s%s%s", _("File Name to Append to"), formatstr, backupstr);
            else
-               i = statusq(1, writefile_list, answer, 0,
+               i = statusq(1, writefile_list, writepath, 0,
                    "%s%s%s", _("File Name to Write"), formatstr, backupstr);
        }
 #else
        if (append == 2)
-           i = statusq(1, writefile_list, answer,
+           i = statusq(1, writefile_list, writepath,
                "%s", _("File Name to Prepend to"));
        else if (append == 1)
-           i = statusq(1, writefile_list, answer,
+           i = statusq(1, writefile_list, writepath,
                "%s", _("File Name to Append to"));
        else
-           i = statusq(1, writefile_list, answer,
+           i = statusq(1, writefile_list, writepath,
                "%s", _("File Name to Write"));
 #endif /* !NANO_SMALL */
 
index b9030ff44d363e640186a518b6eafc93f60ea930..6dc664580975491534c552c62574ffacd694e165 100644 (file)
--- a/search.c
+++ b/search.c
@@ -817,8 +817,12 @@ int do_replace(void)
 
 int do_gotoline(int line, int save_pos)
 {
+    static char *linestr = NULL;
+
+    linestr = mallocstrcpy(linestr, answer);
+
     if (line <= 0) {           /* Ask for it */
-       int st = statusq(FALSE, goto_list, line != 0 ? answer : "",
+       int st = statusq(FALSE, goto_list, line != 0 ? linestr : "",
 #ifndef NANO_SMALL
                        NULL,
 #endif