use bounded string op
This commit is contained in:
parent
7f01f184d4
commit
cad152ee49
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: ch.c,v 1.3 1998/02/04 11:08:41 christos Exp $ */
|
||||
/* $NetBSD: ch.c,v 1.4 2003/08/06 13:36:53 itojun Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1988 Mark Nudleman
|
||||
@ -39,7 +39,7 @@
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)ch.c 8.1 (Berkeley) 6/6/93";
|
||||
#else
|
||||
__RCSID("$NetBSD: ch.c,v 1.3 1998/02/04 11:08:41 christos Exp $");
|
||||
__RCSID("$NetBSD: ch.c,v 1.4 2003/08/06 13:36:53 itojun Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
@ -407,8 +407,8 @@ ch_init(want_nbufs, keep)
|
||||
* If we don't have ANY, then quit.
|
||||
* Otherwise, just report the error and return.
|
||||
*/
|
||||
(void)sprintf(message, "cannot allocate %d buffers",
|
||||
want_nbufs - nbufs);
|
||||
(void)snprintf(message, sizeof(message),
|
||||
"cannot allocate %d buffers", want_nbufs - nbufs);
|
||||
error(message);
|
||||
if (nbufs == 0)
|
||||
quit();
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: command.c,v 1.6 2001/01/04 16:17:14 lukem Exp $ */
|
||||
/* $NetBSD: command.c,v 1.7 2003/08/06 13:36:54 itojun Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1988 Mark Nudleman
|
||||
@ -39,7 +39,7 @@
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)command.c 8.1 (Berkeley) 6/6/93";
|
||||
#else
|
||||
__RCSID("$NetBSD: command.c,v 1.6 2001/01/04 16:17:14 lukem Exp $");
|
||||
__RCSID("$NetBSD: command.c,v 1.7 2003/08/06 13:36:54 itojun Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
@ -185,19 +185,22 @@ prompt()
|
||||
putstr(current_name);
|
||||
putstr(":");
|
||||
if (!ispipe) {
|
||||
(void)sprintf(pbuf, " file %d/%d", curr_ac + 1, ac);
|
||||
(void)snprintf(pbuf, sizeof(pbuf), " file %d/%d",
|
||||
curr_ac + 1, ac);
|
||||
putstr(pbuf);
|
||||
}
|
||||
if (linenums) {
|
||||
(void)sprintf(pbuf, " line %d", currline(BOTTOM));
|
||||
(void)snprintf(pbuf, sizeof(pbuf), " line %d",
|
||||
currline(BOTTOM));
|
||||
putstr(pbuf);
|
||||
}
|
||||
if ((pos = position(BOTTOM)) != NULL_POSITION) {
|
||||
(void)sprintf(pbuf, " byte %lld", (long long)pos);
|
||||
(void)snprintf(pbuf, sizeof(pbuf), " byte %lld",
|
||||
(long long)pos);
|
||||
putstr(pbuf);
|
||||
if (!ispipe && (len = ch_length())) {
|
||||
(void)sprintf(pbuf, "/%lld pct %lld%%",
|
||||
(long long)len,
|
||||
(void)snprintf(pbuf, sizeof(pbuf),
|
||||
"/%lld pct %lld%%", (long long)len,
|
||||
(long long)((100 * pos) / len));
|
||||
putstr(pbuf);
|
||||
}
|
||||
@ -219,7 +222,7 @@ prompt()
|
||||
else if (!ispipe &&
|
||||
(pos = position(BOTTOM)) != NULL_POSITION &&
|
||||
(len = ch_length())) {
|
||||
(void)sprintf(pbuf, " (%lld%%)",
|
||||
(void)snprintf(pbuf, sizeof(pbuf), " (%lld%%)",
|
||||
(long long)((100 * pos) / len));
|
||||
putstr(pbuf);
|
||||
}
|
||||
@ -593,9 +596,10 @@ editfile()
|
||||
dolinenumber = 0;
|
||||
}
|
||||
if (dolinenumber && (c = currline(MIDDLE)))
|
||||
(void)sprintf(buf, "%s +%d %s", editor, c, current_file);
|
||||
(void)snprintf(buf, sizeof(buf), "%s +%d %s", editor, c,
|
||||
current_file);
|
||||
else
|
||||
(void)sprintf(buf, "%s %s", editor, current_file);
|
||||
(void)snprintf(buf, sizeof(buf), "%s %s", editor, current_file);
|
||||
lsystem(buf);
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: help.c,v 1.3 1998/02/04 11:08:49 christos Exp $ */
|
||||
/* $NetBSD: help.c,v 1.4 2003/08/06 13:36:54 itojun Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1988 Mark Nudleman
|
||||
@ -39,7 +39,7 @@
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)help.c 8.1 (Berkeley) 6/6/93";
|
||||
#else
|
||||
__RCSID("$NetBSD: help.c,v 1.3 1998/02/04 11:08:49 christos Exp $");
|
||||
__RCSID("$NetBSD: help.c,v 1.4 2003/08/06 13:36:54 itojun Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
@ -55,6 +55,6 @@ help()
|
||||
{
|
||||
char cmd[MAXPATHLEN + 20];
|
||||
|
||||
(void)sprintf(cmd, "-more %s", _PATH_HELPFILE);
|
||||
(void)snprintf(cmd, sizeof(cmd), "-more %s", _PATH_HELPFILE);
|
||||
lsystem(cmd);
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: main.c,v 1.4 1998/02/04 11:08:57 christos Exp $ */
|
||||
/* $NetBSD: main.c,v 1.5 2003/08/06 13:36:54 itojun Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1988 Mark Nudleman
|
||||
@ -46,7 +46,7 @@ __COPYRIGHT(
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)main.c 8.1 (Berkeley) 6/7/93";
|
||||
#else
|
||||
__RCSID("$NetBSD: main.c,v 1.4 1998/02/04 11:08:57 christos Exp $");
|
||||
__RCSID("$NetBSD: main.c,v 1.5 2003/08/06 13:36:54 itojun Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
@ -125,7 +125,8 @@ edit(filename)
|
||||
return(0);
|
||||
}
|
||||
else if ((f = open(filename, O_RDONLY, 0)) < 0) {
|
||||
(void)sprintf(message, "%s: %s", filename, strerror(errno));
|
||||
(void)snprintf(message, sizeof(message), "%s: %s", filename,
|
||||
strerror(errno));
|
||||
error(message);
|
||||
free(filename);
|
||||
return(0);
|
||||
@ -335,13 +336,13 @@ save(s)
|
||||
{
|
||||
char *p;
|
||||
|
||||
p = malloc((u_int)strlen(s)+1);
|
||||
p = strdup(s);
|
||||
if (p == NULL)
|
||||
{
|
||||
error("cannot allocate memory");
|
||||
quit();
|
||||
}
|
||||
return(strcpy(p, s));
|
||||
return(p);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: os.c,v 1.4 1998/02/04 11:09:01 christos Exp $ */
|
||||
/* $NetBSD: os.c,v 1.5 2003/08/06 13:36:54 itojun Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1988 Mark Nudleman
|
||||
@ -39,7 +39,7 @@
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)os.c 8.1 (Berkeley) 6/6/93";
|
||||
#else
|
||||
__RCSID("$NetBSD: os.c,v 1.4 1998/02/04 11:09:01 christos Exp $");
|
||||
__RCSID("$NetBSD: os.c,v 1.5 2003/08/06 13:36:54 itojun Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
@ -134,7 +134,8 @@ lsystem(cmd)
|
||||
cmd = shell;
|
||||
else
|
||||
{
|
||||
(void)sprintf(cmdbuf, "%s -c \"%s\"", shell, cmd);
|
||||
(void)snprintf(cmdbuf, sizeof(cmdbuf), "%s -c \"%s\"",
|
||||
shell, cmd);
|
||||
cmd = cmdbuf;
|
||||
}
|
||||
}
|
||||
@ -212,6 +213,7 @@ glob(filename)
|
||||
int ch;
|
||||
char *cmd;
|
||||
static char buffer[MAXPATHLEN];
|
||||
size_t l;
|
||||
|
||||
if (filename[0] == '#')
|
||||
return (filename);
|
||||
@ -226,26 +228,24 @@ glob(filename)
|
||||
/*
|
||||
* Read the output of <echo filename>.
|
||||
*/
|
||||
cmd = malloc((u_int)(strlen(filename)+8));
|
||||
asprintf(&cmd, "echo \"%s\"", filename);
|
||||
if (cmd == NULL)
|
||||
return (filename);
|
||||
(void)sprintf(cmd, "echo \"%s\"", filename);
|
||||
} else
|
||||
{
|
||||
/*
|
||||
* Read the output of <$SHELL -c "echo filename">.
|
||||
*/
|
||||
cmd = malloc((u_int)(strlen(p)+12));
|
||||
asprintf(&cmd, "%s -c \"echo %s\"", p, filename);
|
||||
if (cmd == NULL)
|
||||
return (filename);
|
||||
(void)sprintf(cmd, "%s -c \"echo %s\"", p, filename);
|
||||
}
|
||||
|
||||
if ((f = popen(cmd, "r")) == NULL)
|
||||
return (filename);
|
||||
free(cmd);
|
||||
|
||||
for (p = buffer; p < &buffer[sizeof(buffer)-1]; p++)
|
||||
for (p = buffer; p < &buffer[sizeof(buffer)-1]; p++)
|
||||
{
|
||||
if ((ch = getc(f)) == '\n' || ch == EOF)
|
||||
break;
|
||||
@ -264,14 +264,15 @@ bad_file(filename, message, len)
|
||||
struct stat statbuf;
|
||||
|
||||
if (stat(filename, &statbuf) < 0) {
|
||||
(void)sprintf(message, "%s: %s", filename, strerror(errno));
|
||||
(void)snprintf(message, len, "%s: %s", filename,
|
||||
strerror(errno));
|
||||
return(message);
|
||||
}
|
||||
if ((statbuf.st_mode & S_IFMT) == S_IFDIR) {
|
||||
static char is_dir[] = " is a directory";
|
||||
|
||||
strtcpy(message, filename, (int)(len-sizeof(is_dir)-1));
|
||||
(void)strcat(message, is_dir);
|
||||
(void)strlcat(message, is_dir, len);
|
||||
return(message);
|
||||
}
|
||||
return((char *)NULL);
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: prim.c,v 1.6 2001/08/20 12:00:47 wiz Exp $ */
|
||||
/* $NetBSD: prim.c,v 1.7 2003/08/06 13:36:54 itojun Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1988 Mark Nudleman
|
||||
@ -39,7 +39,7 @@
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)prim.c 8.1 (Berkeley) 6/6/93";
|
||||
#else
|
||||
__RCSID("$NetBSD: prim.c,v 1.6 2001/08/20 12:00:47 wiz Exp $");
|
||||
__RCSID("$NetBSD: prim.c,v 1.7 2003/08/06 13:36:54 itojun Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
@ -697,7 +697,7 @@ search(search_forward, pattern, n, wantmatch)
|
||||
pattern = last_pattern;
|
||||
} else
|
||||
{
|
||||
(void)strcpy(lpbuf, pattern);
|
||||
(void)strlcpy(lpbuf, pattern, sizeof(lpbuf));
|
||||
last_pattern = lpbuf;
|
||||
}
|
||||
#endif
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: screen.c,v 1.4 1998/02/04 11:09:10 christos Exp $ */
|
||||
/* $NetBSD: screen.c,v 1.5 2003/08/06 13:36:54 itojun Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1988 Mark Nudleman
|
||||
@ -39,7 +39,7 @@
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)screen.c 8.2 (Berkeley) 4/20/94";
|
||||
#else
|
||||
__RCSID("$NetBSD: screen.c,v 1.4 1998/02/04 11:09:10 christos Exp $");
|
||||
__RCSID("$NetBSD: screen.c,v 1.5 2003/08/06 13:36:54 itojun Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
@ -263,7 +263,7 @@ get_term()
|
||||
if ((term = getenv("TERM")) == NULL)
|
||||
term = "unknown";
|
||||
if (tgetent(termbuf, term) <= 0)
|
||||
(void)strcpy(termbuf, "dumb:co#80:hc:");
|
||||
(void)strlcpy(termbuf, "dumb:co#80:hc:", sizeof(termbuf));
|
||||
|
||||
/*
|
||||
* Get size of the screen.
|
||||
@ -400,7 +400,8 @@ get_term()
|
||||
* No "home" string,
|
||||
* but we can use "move(0,0)".
|
||||
*/
|
||||
(void)strcpy(sp, tgoto(sc_move, 0, 0));
|
||||
(void)strlcpy(sp, tgoto(sc_move, 0, 0),
|
||||
sizeof(sbuf) - (sp - sbuf));
|
||||
sc_home = sp;
|
||||
sp += strlen(sp) + 1;
|
||||
}
|
||||
@ -418,7 +419,8 @@ get_term()
|
||||
* No "lower-left" string,
|
||||
* but we can use "move(0,last-line)".
|
||||
*/
|
||||
(void)strcpy(sp, tgoto(sc_move, 0, sc_height-1));
|
||||
(void)strlcpy(sp, tgoto(sc_move, 0, sc_height-1),
|
||||
sizeof(sbuf) - (sp - sbuf));
|
||||
sc_lower_left = sp;
|
||||
sp += strlen(sp) + 1;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user