use bounded string op
This commit is contained in:
parent
3e9598d4fa
commit
a69cd45b93
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: eval.c,v 1.72 2003/01/23 14:58:07 agc Exp $ */
|
||||
/* $NetBSD: eval.c,v 1.73 2003/07/13 08:31:13 itojun Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1993
|
||||
|
@ -41,7 +41,7 @@
|
|||
#if 0
|
||||
static char sccsid[] = "@(#)eval.c 8.9 (Berkeley) 6/8/95";
|
||||
#else
|
||||
__RCSID("$NetBSD: eval.c,v 1.72 2003/01/23 14:58:07 agc Exp $");
|
||||
__RCSID("$NetBSD: eval.c,v 1.73 2003/07/13 08:31:13 itojun Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
|
@ -1176,7 +1176,7 @@ execcmd(int argc, char **argv)
|
|||
}
|
||||
|
||||
static int
|
||||
conv_time(clock_t ticks, char *seconds)
|
||||
conv_time(clock_t ticks, char *seconds, size_t l)
|
||||
{
|
||||
static clock_t tpm = 0;
|
||||
clock_t mins;
|
||||
|
@ -1186,12 +1186,12 @@ conv_time(clock_t ticks, char *seconds)
|
|||
tpm = sysconf(_SC_CLK_TCK) * 60;
|
||||
|
||||
mins = ticks / tpm;
|
||||
sprintf(seconds, "%.4f", (ticks - mins * tpm) * 60.0 / tpm );
|
||||
snprintf(seconds, l, "%.4f", (ticks - mins * tpm) * 60.0 / tpm );
|
||||
|
||||
if (seconds[0] == '6' && seconds[1] == '0') {
|
||||
/* 59.99995 got rounded up... */
|
||||
mins++;
|
||||
strcpy(seconds, "0.0");
|
||||
strlcpy(seconds, "0.0", l);
|
||||
return mins;
|
||||
}
|
||||
|
||||
|
@ -1213,10 +1213,10 @@ timescmd(int argc, char **argv)
|
|||
|
||||
times(&tms);
|
||||
|
||||
u = conv_time( tms.tms_utime, us );
|
||||
s = conv_time( tms.tms_stime, ss );
|
||||
cu = conv_time( tms.tms_cutime, cus );
|
||||
cs = conv_time( tms.tms_cstime, css );
|
||||
u = conv_time(tms.tms_utime, us, sizeof(us));
|
||||
s = conv_time(tms.tms_stime, ss, sizeof(ss));
|
||||
cu = conv_time(tms.tms_cutime, cus, sizeof(cus));
|
||||
cs = conv_time(tms.tms_cstime, css, sizeof(css));
|
||||
|
||||
outfmt(out1, "%dm%ss %dm%ss\n%dm%ss %dm%ss\n",
|
||||
u, us, s, ss, cu, cus, cs, css);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: histedit.c,v 1.29 2003/05/04 06:36:50 gmcgarry Exp $ */
|
||||
/* $NetBSD: histedit.c,v 1.30 2003/07/13 08:31:13 itojun Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1993
|
||||
|
@ -41,7 +41,7 @@
|
|||
#if 0
|
||||
static char sccsid[] = "@(#)histedit.c 8.2 (Berkeley) 5/4/95";
|
||||
#else
|
||||
__RCSID("$NetBSD: histedit.c,v 1.29 2003/05/04 06:36:50 gmcgarry Exp $");
|
||||
__RCSID("$NetBSD: histedit.c,v 1.30 2003/07/13 08:31:13 itojun Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
|
@ -367,7 +367,7 @@ histcmd(int argc, char **argv)
|
|||
if (editor) {
|
||||
int fd;
|
||||
INTOFF; /* easier */
|
||||
sprintf(editfile, "%s_shXXXXXX", _PATH_TMP);
|
||||
snprintf(editfile, sizeof(editfile), "%s_shXXXXXX", _PATH_TMP);
|
||||
if ((fd = mkstemp(editfile)) < 0)
|
||||
error("can't create temporary file %s", editfile);
|
||||
if ((efp = fdopen(fd, "w")) == NULL) {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: mkinit.c,v 1.21 2002/11/24 22:35:41 christos Exp $ */
|
||||
/* $NetBSD: mkinit.c,v 1.22 2003/07/13 08:31:13 itojun Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1991, 1993
|
||||
|
@ -47,7 +47,7 @@ static const char copyright[] =
|
|||
static char sccsid[] = "@(#)mkinit.c 8.2 (Berkeley) 5/4/95";
|
||||
#else
|
||||
static const char rcsid[] =
|
||||
"$NetBSD: mkinit.c,v 1.21 2002/11/24 22:35:41 christos Exp $";
|
||||
"$NetBSD: mkinit.c,v 1.22 2003/07/13 08:31:13 itojun Exp $";
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
|
@ -220,7 +220,7 @@ readfile(char *fname)
|
|||
char line2[1024];
|
||||
static const char undef[] = "#undef ";
|
||||
|
||||
strcpy(line2, line);
|
||||
strlcpy(line2, line, sizeof(line2));
|
||||
memcpy(line2, undef, sizeof(undef) - 1);
|
||||
cp = line2 + sizeof(undef) - 1;
|
||||
while(*cp && (*cp == ' ' || *cp == '\t'))
|
||||
|
@ -282,7 +282,7 @@ doevent(struct event *ep, FILE *fp, char *fname)
|
|||
int indent;
|
||||
char *p;
|
||||
|
||||
sprintf(line, "\n /* from %s: */\n", fname);
|
||||
snprintf(line, sizeof(line), "\n /* from %s: */\n", fname);
|
||||
addstr(line, &ep->code);
|
||||
addstr(" {\n", &ep->code);
|
||||
for (;;) {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: mknodes.c,v 1.21 2002/11/24 22:35:41 christos Exp $ */
|
||||
/* $NetBSD: mknodes.c,v 1.22 2003/07/13 08:31:14 itojun Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1991, 1993
|
||||
|
@ -47,7 +47,7 @@ static const char copyright[] =
|
|||
static char sccsid[] = "@(#)mknodes.c 8.2 (Berkeley) 5/4/95";
|
||||
#else
|
||||
static const char rcsid[] =
|
||||
"$NetBSD: mknodes.c,v 1.21 2002/11/24 22:35:41 christos Exp $";
|
||||
"$NetBSD: mknodes.c,v 1.22 2003/07/13 08:31:14 itojun Exp $";
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
|
@ -189,16 +189,16 @@ parsefield(void)
|
|||
fp->name = savestr(name);
|
||||
if (strcmp(type, "nodeptr") == 0) {
|
||||
fp->type = T_NODE;
|
||||
sprintf(decl, "union node *%s", name);
|
||||
snprintf(decl, sizeof(decl), "union node *%s", name);
|
||||
} else if (strcmp(type, "nodelist") == 0) {
|
||||
fp->type = T_NODELIST;
|
||||
sprintf(decl, "struct nodelist *%s", name);
|
||||
snprintf(decl, sizeof(decl), "struct nodelist *%s", name);
|
||||
} else if (strcmp(type, "string") == 0) {
|
||||
fp->type = T_STRING;
|
||||
sprintf(decl, "char *%s", name);
|
||||
snprintf(decl, sizeof(decl), "char *%s", name);
|
||||
} else if (strcmp(type, "int") == 0) {
|
||||
fp->type = T_INT;
|
||||
sprintf(decl, "int %s", name);
|
||||
snprintf(decl, sizeof(decl), "int %s", name);
|
||||
} else if (strcmp(type, "other") == 0) {
|
||||
fp->type = T_OTHER;
|
||||
} else if (strcmp(type, "temp") == 0) {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: mksyntax.c,v 1.27 2003/01/12 20:26:53 christos Exp $ */
|
||||
/* $NetBSD: mksyntax.c,v 1.28 2003/07/13 08:31:14 itojun Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1991, 1993
|
||||
|
@ -47,7 +47,7 @@ static const char copyright[] =
|
|||
static char sccsid[] = "@(#)mksyntax.c 8.2 (Berkeley) 5/4/95";
|
||||
#else
|
||||
static const char rcsid[] =
|
||||
"$NetBSD: mksyntax.c,v 1.27 2003/01/12 20:26:53 christos Exp $";
|
||||
"$NetBSD: mksyntax.c,v 1.28 2003/07/13 08:31:14 itojun Exp $";
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
|
@ -181,7 +181,8 @@ main(int argc, char **argv)
|
|||
/* Generate the #define statements in the header file */
|
||||
fputs("/* Syntax classes */\n", hfile);
|
||||
for (i = 0 ; synclass[i].name ; i++) {
|
||||
sprintf(buf, "#define %s %d", synclass[i].name, i);
|
||||
snprintf(buf, sizeof(buf), "#define %s %d",
|
||||
synclass[i].name, i);
|
||||
fputs(buf, hfile);
|
||||
for (pos = strlen(buf) ; pos < 32 ; pos = (pos + 8) & ~07)
|
||||
putc('\t', hfile);
|
||||
|
@ -190,7 +191,8 @@ main(int argc, char **argv)
|
|||
putc('\n', hfile);
|
||||
fputs("/* Syntax classes for is_ functions */\n", hfile);
|
||||
for (i = 0 ; is_entry[i].name ; i++) {
|
||||
sprintf(buf, "#define %s %#o", is_entry[i].name, 1 << i);
|
||||
snprintf(buf, sizeof(buf), "#define %s %#o",
|
||||
is_entry[i].name, 1 << i);
|
||||
fputs(buf, hfile);
|
||||
for (pos = strlen(buf) ; pos < 32 ; pos = (pos + 8) & ~07)
|
||||
putc('\t', hfile);
|
||||
|
|
Loading…
Reference in New Issue