]> git.wh0rd.org Git - nano.git/commitdiff
real_dir_from_tilde(): ops, fix case where buf =~, silly crash
authorChris Allegretta <chrisa@asty.org>
Mon, 8 Jan 2001 16:59:19 +0000 (16:59 +0000)
committerChris Allegretta <chrisa@asty.org>
Mon, 8 Jan 2001 16:59:19 +0000 (16:59 +0000)
git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@463 35c25a1d-7b9e-4130-9fde-d3aeb78583b8

ChangeLog
files.c

index 3bf62e094d36b5b87c88bd50181db2e1b597146c..9275aab677464d415f3a67e94cde4e80c7820e88 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,8 @@
 CVS code -
+- files.c:
+  real_dir_from_tilde()
+       - Oops, fix case where buf ="~", silly crash (bug discovered by
+         Neil Parks).
 
 nano 0.9.25 - 01/07/2001
 General - 
diff --git a/files.c b/files.c
index c5974174dbca190f6cc9521fa00fe648754a0688..f6656311e1089fc0c90d353b7a7ce1d3817b2896 100644 (file)
--- a/files.c
+++ b/files.c
@@ -589,11 +589,15 @@ char *real_dir_from_tilde(char *buf)
     if (buf[0] == '~') {
        if (buf[1] == '~')
            goto abort;         /* Handle ~~ without segfaulting =) */
-       else if (buf[1] == '/') {
+       else if (buf[1] == 0 || buf[1] == '/') {
            if (getenv("HOME") != NULL) {
                dirtmp = nmalloc(strlen(buf) + 2 + strlen(getenv("HOME")));
 
-               sprintf(dirtmp, "%s/%s", getenv("HOME"), &buf[2]);
+               if (strlen(buf) > 2)
+                   sprintf(dirtmp, "%s/%s", getenv("HOME"), &buf[2]);
+               else
+                   sprintf(dirtmp, "%s/", getenv("HOME"));
+
            }
        } else if (buf[1] != 0) {