diff options
| author | christos <christos@NetBSD.org> | 2021-09-26 13:45:37 +0000 |
|---|---|---|
| committer | christos <christos@NetBSD.org> | 2021-09-26 13:45:37 +0000 |
| commit | 5e8e3daf821c49919f092f98f1f9707e2f280c59 (patch) | |
| tree | bbe745d411002a6c603613dd47d09298bcc9475e /lib/libedit | |
| parent | 7881c6e1861c20a529e9ba9678f7fa0091ac3583 (diff) | |
- Completion should not add a quote at the end of the line to match an
already quoted quote. (Piotr Stefaniak)
- fix lint unconst warnings for strchr
Diffstat (limited to 'lib/libedit')
| -rw-r--r-- | lib/libedit/filecomplete.c | 29 |
1 files changed, 16 insertions, 13 deletions
diff --git a/lib/libedit/filecomplete.c b/lib/libedit/filecomplete.c index 9cdb5481bf8..dff36939cdb 100644 --- a/lib/libedit/filecomplete.c +++ b/lib/libedit/filecomplete.c @@ -1,4 +1,4 @@ -/* $NetBSD: filecomplete.c,v 1.68 2021/05/05 14:49:59 christos Exp $ */ +/* $NetBSD: filecomplete.c,v 1.69 2021/09/26 13:45:37 christos Exp $ */ /*- * Copyright (c) 1997 The NetBSD Foundation, Inc. @@ -31,7 +31,7 @@ #include "config.h" #if !defined(lint) && !defined(SCCSID) -__RCSID("$NetBSD: filecomplete.c,v 1.68 2021/05/05 14:49:59 christos Exp $"); +__RCSID("$NetBSD: filecomplete.c,v 1.69 2021/09/26 13:45:37 christos Exp $"); #endif /* not lint && not SCCSID */ #include <sys/types.h> @@ -69,20 +69,21 @@ fn_tilde_expand(const char *txt) char pwbuf[1024]; #endif struct passwd *pass; + const char *pos; char *temp; size_t len = 0; if (txt[0] != '~') return strdup(txt); - temp = strchr(txt + 1, '/'); - if (temp == NULL) { + pos = strchr(txt + 1, '/'); + if (pos == NULL) { temp = strdup(txt + 1); if (temp == NULL) return NULL; } else { /* text until string after slash */ - len = (size_t)(temp - txt + 1); + len = (size_t)(pos - txt + 1); temp = el_calloc(len, sizeof(*temp)); if (temp == NULL) return NULL; @@ -212,9 +213,10 @@ escape_filename(EditLine * el, const char *filename, int single_match, while (temp != el->el_line.cursor) { /* * If we see a single quote but have not seen a double quote - * so far set/unset s_quote + * so far set/unset s_quote, unless it is already quoted */ - if (temp[0] == '\'' && !d_quoted) + if (temp[0] == '\'' && !d_quoted && + (temp == el->el_line.buffer || temp[-1] != '\\')) s_quoted = !s_quoted; /* * vice versa to the above condition @@ -327,14 +329,15 @@ fn_filename_completion_function(const char *text, int state) static size_t filename_len = 0; struct dirent *entry; char *temp; + const char *pos; size_t len; if (state == 0 || dir == NULL) { - temp = strrchr(text, '/'); - if (temp) { + pos = strrchr(text, '/'); + if (pos) { char *nptr; - temp++; - nptr = el_realloc(filename, (strlen(temp) + 1) * + pos++; + nptr = el_realloc(filename, (strlen(pos) + 1) * sizeof(*nptr)); if (nptr == NULL) { el_free(filename); @@ -342,8 +345,8 @@ fn_filename_completion_function(const char *text, int state) return NULL; } filename = nptr; - (void)strcpy(filename, temp); - len = (size_t)(temp - text); /* including last slash */ + (void)strcpy(filename, pos); + len = (size_t)(pos - text); /* including last slash */ nptr = el_realloc(dirname, (len + 1) * sizeof(*nptr)); |
