nano

nano with my custom patches
git clone git://bsandro.tech/nano
Log | Files | Refs | README | LICENSE

commit 62eeda3e9f5d75a8fcb7c02f1846d13c062cc895
parent 06c806215e66f74d231176a53275ce7776e2f997
Author: Benno Schulenberg <bensberg@justemail.net>
Date:   Mon, 11 Jul 2016 20:39:53 +0200

tweaks: use mallocstrcpy() instead of strdup(), for a graceful death

To make nano save its modified buffers when it runs out of memory.

Diffstat:
Msrc/browser.c | 6+++---
Msrc/utils.c | 2+-
2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/browser.c b/src/browser.c @@ -315,7 +315,7 @@ char *do_browser(char *path) present_name = striponedir(filelist[selected]); /* Try opening and reading the selected directory. */ - newpath = strdup(filelist[selected]); + newpath = mallocstrcpy(NULL, filelist[selected]); goto read_directory_contents; } else if (func == do_exit) { /* Exit from the file browser. */ @@ -331,9 +331,9 @@ char *do_browser(char *path) /* If the window resized, refresh the file list. */ if (kbinput == KEY_WINCH) { /* Remember the selected file, to be able to reselect it. */ - present_name = strdup(filelist[selected]); + present_name = mallocstrcpy(NULL, filelist[selected]); /* Reread the contents of the current directory. */ - newpath = strdup(present_path); + newpath = mallocstrcpy(NULL, present_path); goto read_directory_contents; } #endif diff --git a/src/utils.c b/src/utils.c @@ -99,7 +99,7 @@ bool parse_line_column(const char *str, ssize_t *line, ssize_t *column) if (comma == str) return TRUE; - firstpart = strdup(str); + firstpart = mallocstrcpy(NULL, str); firstpart[comma - str] = '\0'; retval = parse_num(firstpart, line);