diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 2003-03-18 16:55:55 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 2003-03-18 16:55:55 +0000 |
commit | dfbb771c83664afc246a3834d4ec17f3169b5989 (patch) | |
tree | a6062cdd0136c3b4f82635b600a22a9bb6099569 /lib/libcurses/trace | |
parent | 9504d3161dd42533b38ffc7e455b079baddb6032 (diff) |
Use strlcpy() / strlcat() throughout.
Diffstat (limited to 'lib/libcurses/trace')
-rw-r--r-- | lib/libcurses/trace/lib_traceatr.c | 25 | ||||
-rw-r--r-- | lib/libcurses/trace/lib_tracebits.c | 36 | ||||
-rw-r--r-- | lib/libcurses/trace/lib_tracemse.c | 6 |
3 files changed, 34 insertions, 33 deletions
diff --git a/lib/libcurses/trace/lib_traceatr.c b/lib/libcurses/trace/lib_traceatr.c index 57c2ad5fc76..e1b813bc3d9 100644 --- a/lib/libcurses/trace/lib_traceatr.c +++ b/lib/libcurses/trace/lib_traceatr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lib_traceatr.c,v 1.4 2003/03/17 19:16:59 millert Exp $ */ +/* $OpenBSD: lib_traceatr.c,v 1.5 2003/03/18 16:55:54 millert Exp $ */ /**************************************************************************** * Copyright (c) 1998,2000 Free Software Foundation, Inc. * @@ -89,13 +89,14 @@ _traceattr2(int bufnum, attr_t newmode) unsigned save_nc_tracing = _nc_tracing; _nc_tracing = 0; - strcpy(tmp++, "{"); + *tmp++ = '{'; + *tmp = '\0'; for (n = 0; n < SIZEOF(names); n++) { if ((newmode & names[n].val) != 0) { if (buf[1] != '\0') - strcat(tmp, "|"); - strcat(tmp, names[n].name); + strlcat(tmp, "|", BUFSIZ - (tmp - buf)); + strlcat(tmp, names[n].name, BUFSIZ - (tmp - buf)); tmp += strlen(tmp); if (names[n].val == A_COLOR) { @@ -116,12 +117,13 @@ _traceattr2(int bufnum, attr_t newmode) } if (AttrOf(newmode) == A_NORMAL) { if (buf[1] != '\0') - strcat(tmp, "|"); - strcat(tmp, "A_NORMAL"); + strlcat(tmp, "|", BUFSIZ - (tmp - buf)); + strlcat(tmp, "A_NORMAL", BUFSIZ - (tmp - buf)); } _nc_tracing = save_nc_tracing; - return (strcat(buf, "}")); + strlcat(buf, "}", BUFSIZ); + return (buf); } NCURSES_EXPORT(char *) @@ -144,7 +146,8 @@ _tracechtype2(int bufnum, chtype ch) char *buf = _nc_trace_buf(bufnum, BUFSIZ); char *found = 0; - strcpy(buf, "{"); + buf[0] = '{'; + buf[1] = '\0'; if (ch & A_ALTCHARSET) { char *cp; static const struct { @@ -201,7 +204,7 @@ _tracechtype2(int bufnum, chtype ch) ch = TextOf(*found); for (sp = names; sp->val; sp++) if (sp->val == ch) { - (void) strcat(buf, sp->name); + (void) strlcat(buf, sp->name, BUFSIZ); ch &= ~A_ALTCHARSET; break; } @@ -209,13 +212,13 @@ _tracechtype2(int bufnum, chtype ch) } if (found == 0) - (void) strcat(buf, _tracechar(TextOf(ch))); + (void) strlcat(buf, _tracechar(TextOf(ch)), BUFSIZ); if (AttrOf(ch) != A_NORMAL) (void) snprintf(buf + strlen(buf), BUFSIZ - strlen(buf), " | %s", _traceattr2(bufnum + 20, AttrOf(ch))); - strcat(buf, "}"); + strlcat(buf, "}", BUFSIZ); return (buf); } diff --git a/lib/libcurses/trace/lib_tracebits.c b/lib/libcurses/trace/lib_tracebits.c index 3d7fb492884..b1ad17da12c 100644 --- a/lib/libcurses/trace/lib_tracebits.c +++ b/lib/libcurses/trace/lib_tracebits.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lib_tracebits.c,v 1.8 2001/01/22 18:01:58 millert Exp $ */ +/* $OpenBSD: lib_tracebits.c,v 1.9 2003/03/18 16:55:54 millert Exp $ */ /**************************************************************************** * Copyright (c) 1998,1999,2000 Free Software Foundation, Inc. * @@ -66,21 +66,21 @@ typedef struct { } BITNAMES; static void -lookup_bits(char *buf, const BITNAMES * table, const char *label, unsigned int val) +lookup_bits(char *buf, size_t bufsize, const BITNAMES * table, const char *label, unsigned int val) { const BITNAMES *sp; - (void) strcat(buf, label); - (void) strcat(buf, ": {"); + (void) strlcat(buf, label, bufsize); + (void) strlcat(buf, ": {", bufsize); for (sp = table; sp->name; sp++) if (sp->val != 0 && (val & sp->val) == sp->val) { - (void) strcat(buf, sp->name); - (void) strcat(buf, ", "); + (void) strlcat(buf, sp->name, bufsize); + (void) strlcat(buf, ", ", bufsize); } if (buf[strlen(buf) - 2] == ',') buf[strlen(buf) - 2] = '\0'; - (void) strcat(buf, "} "); + (void) strlcat(buf, "} ", bufsize); } NCURSES_EXPORT(char *) @@ -88,6 +88,7 @@ _nc_tracebits(void) /* describe the state of the terminal control bits exactly */ { char *buf; + size_t bufsize; #ifdef TERMIOS static const BITNAMES iflags[] = @@ -138,21 +139,18 @@ _nc_tracebits(void) #define ALLLOCAL (ECHO|ECHONL|ICANON|ISIG|NOFLSH|TOSTOP|IEXTEN) }; - buf = _nc_trace_buf(0, - 8 + sizeof(iflags) + - 8 + sizeof(oflags) + - 8 + sizeof(cflags) + - 8 + sizeof(lflags) + - 8); + bufsize = 8 + sizeof(iflags) + 8 + sizeof(oflags) + 8 + sizeof(cflags) + + 8 + sizeof(lflags) + 8; + buf = _nc_trace_buf(0, bufsize); if (cur_term->Nttyb.c_iflag & ALLIN) - lookup_bits(buf, iflags, "iflags", cur_term->Nttyb.c_iflag); + lookup_bits(buf, bufsize, iflags, "iflags", cur_term->Nttyb.c_iflag); if (cur_term->Nttyb.c_oflag & ALLOUT) - lookup_bits(buf, oflags, "oflags", cur_term->Nttyb.c_oflag); + lookup_bits(buf, bufsize, oflags, "oflags", cur_term->Nttyb.c_oflag); if (cur_term->Nttyb.c_cflag & ALLCTRL) - lookup_bits(buf, cflags, "cflags", cur_term->Nttyb.c_cflag); + lookup_bits(buf, bufsize, cflags, "cflags", cur_term->Nttyb.c_cflag); #if defined(CS5) && defined(CS8) { @@ -189,12 +187,12 @@ _nc_tracebits(void) } } } - strcat(buf, result); + strlcat(buf, result, bufsize); } #endif if (cur_term->Nttyb.c_lflag & ALLLOCAL) - lookup_bits(buf, lflags, "lflags", cur_term->Nttyb.c_lflag); + lookup_bits(buf, bufsize, lflags, "lflags", cur_term->Nttyb.c_lflag); #else /* reference: ttcompat(4M) on SunOS 4.1 */ @@ -234,7 +232,7 @@ _nc_tracebits(void) 8 + sizeof(cflags)); if (cur_term->Nttyb.sg_flags & ALLCTRL) { - lookup_bits(buf, cflags, "cflags", cur_term->Nttyb.sg_flags); + lookup_bits(buf, bufsize, cflags, "cflags", cur_term->Nttyb.sg_flags); } #endif return (buf); diff --git a/lib/libcurses/trace/lib_tracemse.c b/lib/libcurses/trace/lib_tracemse.c index fe0555eb07f..3346d87e224 100644 --- a/lib/libcurses/trace/lib_tracemse.c +++ b/lib/libcurses/trace/lib_tracemse.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lib_tracemse.c,v 1.3 2003/03/17 19:16:59 millert Exp $ */ +/* $OpenBSD: lib_tracemse.c,v 1.4 2003/03/18 16:55:54 millert Exp $ */ /**************************************************************************** * Copyright (c) 1998,2000 Free Software Foundation, Inc. * @@ -51,7 +51,7 @@ _tracemouse(MEVENT const *ep) (void) snprintf(buf, sizeof(buf), "id %2d at (%2d, %2d, %2d) state %4lx = {", ep->id, ep->x, ep->y, ep->z, ep->bstate); -#define SHOW(m, s) if ((ep->bstate & m)==m) {strcat(buf,s); strcat(buf, ", ");} +#define SHOW(m, s) if ((ep->bstate & m)==m) {strlcat(buf,s,sizeof(buf)); strlcat(buf, ", ",sizeof(buf));} SHOW(BUTTON1_RELEASED, "release-1") SHOW(BUTTON1_PRESSED, "press-1") SHOW(BUTTON1_CLICKED, "click-1") @@ -85,7 +85,7 @@ _tracemouse(MEVENT const *ep) if (buf[strlen(buf) - 1] == ' ') buf[strlen(buf) - 2] = '\0'; - (void) strcat(buf, "}"); + (void) strlcat(buf, "}", sizeof(buf)); return (buf); } |