* implement xsl_init() and xsl_add(); error checking forms of sl_{init,add}()
* fix bug where the second press of <TAB> on an empty word (i.e, list all options) may have resulted in an strncmp() against NULL. (detected by _DIAGASSERT())
This commit is contained in:
parent
71cc75d706
commit
d0090fb777
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: complete.c,v 1.35 1999/11/26 21:41:55 lukem Exp $ */
|
||||
/* $NetBSD: complete.c,v 1.36 1999/11/28 06:32:04 lukem Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1997-1999 The NetBSD Foundation, Inc.
|
||||
|
@ -38,7 +38,7 @@
|
|||
|
||||
#include <sys/cdefs.h>
|
||||
#ifndef lint
|
||||
__RCSID("$NetBSD: complete.c,v 1.35 1999/11/26 21:41:55 lukem Exp $");
|
||||
__RCSID("$NetBSD: complete.c,v 1.36 1999/11/28 06:32:04 lukem Exp $");
|
||||
#endif /* not lint */
|
||||
|
||||
/*
|
||||
|
@ -147,14 +147,14 @@ complete_command(word, list)
|
|||
size_t wordlen;
|
||||
unsigned char rv;
|
||||
|
||||
words = sl_init();
|
||||
words = xsl_init();
|
||||
wordlen = strlen(word);
|
||||
|
||||
for (c = cmdtab; c->c_name != NULL; c++) {
|
||||
if (wordlen > strlen(c->c_name))
|
||||
continue;
|
||||
if (strncmp(word, c->c_name, wordlen) == 0)
|
||||
sl_add(words, c->c_name);
|
||||
xsl_add(words, c->c_name);
|
||||
}
|
||||
|
||||
rv = complete_ambiguous(word, list, words);
|
||||
|
@ -206,8 +206,7 @@ complete_local(word, list)
|
|||
if ((dd = opendir(dir)) == NULL)
|
||||
return (CC_ERROR);
|
||||
|
||||
words = sl_init();
|
||||
|
||||
words = xsl_init();
|
||||
len = strlen(file);
|
||||
|
||||
for (dp = readdir(dd); dp != NULL; dp = readdir(dd)) {
|
||||
|
@ -225,7 +224,7 @@ complete_local(word, list)
|
|||
char *tcp;
|
||||
|
||||
tcp = xstrdup(dp->d_name);
|
||||
sl_add(words, tcp);
|
||||
xsl_add(words, tcp);
|
||||
}
|
||||
}
|
||||
closedir(dd);
|
||||
|
@ -264,14 +263,14 @@ complete_option(word, list)
|
|||
size_t wordlen;
|
||||
unsigned char rv;
|
||||
|
||||
words = sl_init();
|
||||
words = xsl_init();
|
||||
wordlen = strlen(word);
|
||||
|
||||
for (o = optiontab; o->name != NULL; o++) {
|
||||
if (wordlen > strlen(o->name))
|
||||
continue;
|
||||
if (strncmp(word, o->name, wordlen) == 0)
|
||||
sl_add(words, o->name);
|
||||
xsl_add(words, o->name);
|
||||
}
|
||||
|
||||
rv = complete_ambiguous(word, list, words);
|
||||
|
@ -319,7 +318,7 @@ complete_remote(word, list)
|
|||
|
||||
if (dirlist != NULL)
|
||||
sl_free(dirlist, 1);
|
||||
dirlist = sl_init();
|
||||
dirlist = xsl_init();
|
||||
|
||||
mflag = 1;
|
||||
emesg = NULL;
|
||||
|
@ -338,7 +337,7 @@ complete_remote(word, list)
|
|||
else
|
||||
tcp = cp;
|
||||
tcp = xstrdup(tcp);
|
||||
sl_add(dirlist, tcp);
|
||||
xsl_add(dirlist, tcp);
|
||||
}
|
||||
if (emesg != NULL) {
|
||||
fprintf(ttyout, "\n%s\n", emesg);
|
||||
|
@ -348,13 +347,13 @@ complete_remote(word, list)
|
|||
dirchange = 0;
|
||||
}
|
||||
|
||||
words = sl_init();
|
||||
words = xsl_init();
|
||||
for (i = 0; i < dirlist->sl_cur; i++) {
|
||||
cp = dirlist->sl_str[i];
|
||||
if (strlen(file) > strlen(cp))
|
||||
continue;
|
||||
if (strncmp(file, cp, strlen(file)) == 0)
|
||||
sl_add(words, cp);
|
||||
xsl_add(words, cp);
|
||||
}
|
||||
rv = complete_ambiguous(file, list, words);
|
||||
sl_free(words, 0);
|
||||
|
@ -393,7 +392,8 @@ complete(el, ch)
|
|||
dolist = 0;
|
||||
/* if cursor and word is same, list alternatives */
|
||||
if (lastc_argc == cursor_argc && lastc_argo == cursor_argo
|
||||
&& strncmp(word, margv[cursor_argc], cursor_argo) == 0)
|
||||
&& strncmp(word, margv[cursor_argc] ? margv[cursor_argc] : "",
|
||||
cursor_argo) == 0)
|
||||
dolist = 1;
|
||||
else if (cursor_argc < margc)
|
||||
(void)strlcpy(word, margv[cursor_argc], cursor_argo + 1);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: extern.h,v 1.50 1999/11/12 02:50:38 lukem Exp $ */
|
||||
/* $NetBSD: extern.h,v 1.51 1999/11/28 06:32:05 lukem Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1996-1999 The NetBSD Foundation, Inc.
|
||||
|
@ -250,6 +250,8 @@ void user __P((int, char **));
|
|||
int xconnect __P((int, const struct sockaddr *, int));
|
||||
int xlisten __P((int, int));
|
||||
void *xmalloc __P((size_t));
|
||||
StringList *xsl_init __P((void));
|
||||
void xsl_add __P((StringList *, char *));
|
||||
char *xstrdup __P((const char *));
|
||||
sig_t xsignal __P((int, void (func) __P((int))));
|
||||
sig_t xsignal_restart __P((int, void (func) __P((int)), int));
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: main.c,v 1.68 1999/11/26 21:41:56 lukem Exp $ */
|
||||
/* $NetBSD: main.c,v 1.69 1999/11/28 06:32:05 lukem Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1996-1999 The NetBSD Foundation, Inc.
|
||||
|
@ -108,7 +108,7 @@ __COPYRIGHT("@(#) Copyright (c) 1985, 1989, 1993, 1994\n\
|
|||
#if 0
|
||||
static char sccsid[] = "@(#)main.c 8.6 (Berkeley) 10/9/94";
|
||||
#else
|
||||
__RCSID("$NetBSD: main.c,v 1.68 1999/11/26 21:41:56 lukem Exp $");
|
||||
__RCSID("$NetBSD: main.c,v 1.69 1999/11/28 06:32:05 lukem Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
|
@ -211,7 +211,7 @@ main(argc, argv)
|
|||
if (sndbuf_size <= 0)
|
||||
sndbuf_size = 8192;
|
||||
|
||||
marg_sl = sl_init();
|
||||
marg_sl = xsl_init();
|
||||
if ((tmpdir = getenv("TMPDIR")) == NULL)
|
||||
tmpdir = _PATH_TMP;
|
||||
|
||||
|
@ -692,7 +692,7 @@ makeargv()
|
|||
marg_sl->sl_cur = 0; /* reset to start of marg_sl */
|
||||
for (margc = 0; ; margc++) {
|
||||
argp = slurpstring();
|
||||
sl_add(marg_sl, argp);
|
||||
xsl_add(marg_sl, argp);
|
||||
if (argp == NULL)
|
||||
break;
|
||||
}
|
||||
|
@ -874,13 +874,13 @@ help(argc, argv)
|
|||
if (argc == 1) {
|
||||
StringList *buf;
|
||||
|
||||
buf = sl_init();
|
||||
buf = xsl_init();
|
||||
fprintf(ttyout,
|
||||
"%sommands may be abbreviated. Commands are:\n\n",
|
||||
proxy ? "Proxy c" : "C");
|
||||
for (c = cmdtab; (p = c->c_name) != NULL; c++)
|
||||
if (!proxy || c->c_proxy)
|
||||
sl_add(buf, p);
|
||||
xsl_add(buf, p);
|
||||
list_vertical(buf);
|
||||
sl_free(buf, 0);
|
||||
return;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: util.c,v 1.84 1999/11/27 01:00:06 lukem Exp $ */
|
||||
/* $NetBSD: util.c,v 1.85 1999/11/28 06:32:05 lukem Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1997-1999 The NetBSD Foundation, Inc.
|
||||
|
@ -75,7 +75,7 @@
|
|||
|
||||
#include <sys/cdefs.h>
|
||||
#ifndef lint
|
||||
__RCSID("$NetBSD: util.c,v 1.84 1999/11/27 01:00:06 lukem Exp $");
|
||||
__RCSID("$NetBSD: util.c,v 1.85 1999/11/28 06:32:05 lukem Exp $");
|
||||
#endif /* not lint */
|
||||
|
||||
/*
|
||||
|
@ -1422,6 +1422,33 @@ xmalloc(size)
|
|||
return (p);
|
||||
}
|
||||
|
||||
/*
|
||||
* sl_init() with inbuilt error checking
|
||||
*/
|
||||
StringList *
|
||||
xsl_init()
|
||||
{
|
||||
StringList *p;
|
||||
|
||||
p = sl_init();
|
||||
if (p == NULL)
|
||||
err(1, "Unable to allocate memory for stringlist");
|
||||
return (p);
|
||||
}
|
||||
|
||||
/*
|
||||
* sl_add() with inbuilt error checking
|
||||
*/
|
||||
void
|
||||
xsl_add(sl, i)
|
||||
StringList *sl;
|
||||
char *i;
|
||||
{
|
||||
|
||||
if (sl_add(sl, i) == -1)
|
||||
err(1, "Unable to add `%s' to stringlist", i);
|
||||
}
|
||||
|
||||
/*
|
||||
* strdup() with inbuilt error checking
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue