From 7c7c0792419d84be43fd4548aeef027ec44db756 Mon Sep 17 00:00:00 2001 From: Chris Allegretta Date: Sat, 26 Jun 2004 00:23:40 +0000 Subject: [PATCH] Christian Weisgerber's fixes for answer corruption in files.c git-svn-id: svn://svn.savannah.gnu.org/nano/branches/nano_1_2_branch/nano@1821 35c25a1d-7b9e-4130-9fde-d3aeb78583b8 --- ChangeLog | 3 +++ files.c | 17 +++++++++-------- search.c | 6 +++++- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3ec9854a..a080b762 100644 --- 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 43fe0fb7..90716a8e 100644 --- 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 */ diff --git a/search.c b/search.c index b9030ff4..6dc66458 100644 --- 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 -- 2.39.5