diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 2002-05-25 09:11:03 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 2002-05-25 09:11:03 +0000 |
commit | c2bdd02a7eec1135cef3ddd6fdc3269a775e544e (patch) | |
tree | ed29df48776d230e00a4e07eeac5fca8955ce494 | |
parent | da8f4ecf268cdf594ae61878f9754ef93b6aa5d7 (diff) |
remaining easy snprintf conversions
-rw-r--r-- | lib/libc/gmon/gmon.c | 6 | ||||
-rw-r--r-- | lib/libc/regex/engine.c | 8 | ||||
-rw-r--r-- | lib/libc/regex/regerror.c | 14 | ||||
-rw-r--r-- | lib/libc/time/strftime.c | 18 |
4 files changed, 24 insertions, 22 deletions
diff --git a/lib/libc/gmon/gmon.c b/lib/libc/gmon/gmon.c index fa828c054fe..abf1bab0936 100644 --- a/lib/libc/gmon/gmon.c +++ b/lib/libc/gmon/gmon.c @@ -32,7 +32,7 @@ */ #if !defined(lint) && defined(LIBC_SCCS) -static char rcsid[] = "$OpenBSD: gmon.c,v 1.12 2002/02/16 21:27:23 millert Exp $"; +static char rcsid[] = "$OpenBSD: gmon.c,v 1.13 2002/05/25 09:11:02 deraadt Exp $"; #endif #include <sys/param.h> @@ -223,7 +223,7 @@ _mcleanup() perror("mcount: gmon.log"); return; } - len = sprintf(dbuf, "[mcleanup1] kcount 0x%x ssiz %d\n", + len = snprintf(dbuf, sizeof dbuf, "[mcleanup1] kcount 0x%x ssiz %d\n", p->kcount, p->kcountsize); write(log, dbuf, len); #endif @@ -245,7 +245,7 @@ _mcleanup() for (toindex = p->froms[fromindex]; toindex != 0; toindex = p->tos[toindex].link) { #ifdef DEBUG - len = sprintf(dbuf, + len = snprintf(dbuf, sizeof dbuf, "[mcleanup2] frompc 0x%x selfpc 0x%x count %d\n" , frompc, p->tos[toindex].selfpc, p->tos[toindex].count); diff --git a/lib/libc/regex/engine.c b/lib/libc/regex/engine.c index d5f0d2f3e84..c272093217d 100644 --- a/lib/libc/regex/engine.c +++ b/lib/libc/regex/engine.c @@ -1,4 +1,4 @@ -/* $OpenBSD: engine.c,v 1.5 2002/02/16 21:27:24 millert Exp $ */ +/* $OpenBSD: engine.c,v 1.6 2002/05/25 09:11:02 deraadt Exp $ */ /*- * Copyright (c) 1992, 1993, 1994 Henry Spencer. @@ -40,7 +40,7 @@ */ #if defined(SNAMES) && defined(LIBC_SCCS) && !defined(lint) -static char enginercsid[] = "$OpenBSD: engine.c,v 1.5 2002/02/16 21:27:24 millert Exp $"; +static char enginercsid[] = "$OpenBSD: engine.c,v 1.6 2002/05/25 09:11:02 deraadt Exp $"; #endif /* SNAMES and LIBC_SCCS and not lint */ /* @@ -1078,9 +1078,9 @@ int ch; static char pbuf[10]; if (isprint(ch) || ch == ' ') - (void)sprintf(pbuf, "%c", ch); + (void)snprintf(pbuf, sizeof pbuf, "%c", ch); else - (void)sprintf(pbuf, "\\%o", ch); + (void)snprintf(pbuf, sizeof pbuf, "\\%o", ch); return(pbuf); } #endif diff --git a/lib/libc/regex/regerror.c b/lib/libc/regex/regerror.c index 976a7d6bc4e..8664772a27d 100644 --- a/lib/libc/regex/regerror.c +++ b/lib/libc/regex/regerror.c @@ -41,7 +41,7 @@ #if 0 static char sccsid[] = "@(#)regerror.c 8.4 (Berkeley) 3/20/94"; #else -static char rcsid[] = "$OpenBSD: regerror.c,v 1.8 2002/05/24 21:22:37 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: regerror.c,v 1.9 2002/05/25 09:11:02 deraadt Exp $"; #endif #endif /* LIBC_SCCS and not lint */ @@ -61,7 +61,7 @@ extern "C" { #endif /* === regerror.c === */ -static char *regatoi(const regex_t *preg, char *localbuf); +static char *regatoi(const regex_t *preg, char *localbuf, int localbufsize); #ifdef __cplusplus } @@ -130,7 +130,7 @@ size_t errbuf_size; char convbuf[50]; if (errcode == REG_ATOI) - s = regatoi(preg, convbuf); + s = regatoi(preg, convbuf, sizeof convbuf); else { for (r = rerrs; r->code != 0; r++) if (r->code == target) @@ -141,7 +141,8 @@ size_t errbuf_size; assert(strlen(r->name) < sizeof(convbuf)); (void) strlcpy(convbuf, r->name, sizeof convbuf); } else - (void)sprintf(convbuf, "REG_0x%x", target); + (void)snprintf(convbuf, sizeof convbuf, + "REG_0x%x", target); s = convbuf; } else s = r->explain; @@ -160,9 +161,10 @@ size_t errbuf_size; == static char *regatoi(const regex_t *preg, char *localbuf); */ static char * -regatoi(preg, localbuf) +regatoi(preg, localbuf, localbufsize) const regex_t *preg; char *localbuf; +int localbufsize; { register struct rerr *r; @@ -172,6 +174,6 @@ char *localbuf; if (r->code == 0) return("0"); - (void)sprintf(localbuf, "%d", r->code); + (void)snprintf(localbuf, localbufsize, "%d", r->code); return(localbuf); } diff --git a/lib/libc/time/strftime.c b/lib/libc/time/strftime.c index 3c2b8e3177c..ea0059a360f 100644 --- a/lib/libc/time/strftime.c +++ b/lib/libc/time/strftime.c @@ -1,6 +1,6 @@ #if defined(LIBC_SCCS) && !defined(lint) && !defined(NOID) static char elsieid[] = "@(#)strftime.c 7.64"; -static char *rcsid = "$OpenBSD: strftime.c,v 1.8 2002/04/04 19:12:09 millert Exp $"; +static char *rcsid = "$OpenBSD: strftime.c,v 1.9 2002/05/25 09:11:02 deraadt Exp $"; #endif /* LIBC_SCCS and not lint */ #include "private.h" @@ -331,10 +331,10 @@ label: tm = *t; mkt = mktime(&tm); if (TYPE_SIGNED(time_t)) - (void) sprintf(buf, "%ld", - (long) mkt); - else (void) sprintf(buf, "%lu", - (unsigned long) mkt); + (void) snprintf(buf, sizeof buf, + "%ld", (long) mkt); + else (void) snprintf(buf, sizeof buf, + "%lu", (unsigned long) mkt); pt = _add(buf, pt, ptlim); } continue; @@ -584,7 +584,7 @@ const char * const ptlim; { char buf[INT_STRLEN_MAXIMUM(int) + 1]; - (void) sprintf(buf, format, n); + (void) snprintf(buf, sizeof buf, format, n); return _add(buf, pt, ptlim); } @@ -648,15 +648,15 @@ _loc P((void)) ((sizeof locale_home) + namesize + (sizeof lc_time))) goto no_locale; oldsun = 0; - (void) sprintf(filename, "%s/%s/%s", locale_home, name, lc_time); + (void) snprintf(filename, "%s/%s/%s", locale_home, name, lc_time); fd = open(filename, O_RDONLY); if (fd < 0) { /* ** Old Sun systems have a different naming and data convention. */ oldsun = 1; - (void) sprintf(filename, "%s/%s/%s", locale_home, - lc_time, name); + (void) snprintf(filename, sizeof filename, "%s/%s/%s", + locale_home, lc_time, name); fd = open(filename, O_RDONLY); if (fd < 0) goto no_locale; |