diff options
-rw-r--r-- | usr.bin/mg/cinfo.c | 14 | ||||
-rw-r--r-- | usr.bin/mg/def.h | 7 | ||||
-rw-r--r-- | usr.bin/mg/echo.c | 21 | ||||
-rw-r--r-- | usr.bin/mg/extend.c | 8 | ||||
-rw-r--r-- | usr.bin/mg/help.c | 26 | ||||
-rw-r--r-- | usr.bin/mg/kbd.c | 7 | ||||
-rw-r--r-- | usr.bin/mg/main.c | 3 |
7 files changed, 42 insertions, 44 deletions
diff --git a/usr.bin/mg/cinfo.c b/usr.bin/mg/cinfo.c index 429c57f3f68..c2d9a775b90 100644 --- a/usr.bin/mg/cinfo.c +++ b/usr.bin/mg/cinfo.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cinfo.c,v 1.5 2001/05/23 22:20:35 art Exp $ */ +/* $OpenBSD: cinfo.c,v 1.6 2001/05/23 23:29:47 mickey Exp $ */ /* * Character class tables. @@ -17,7 +17,7 @@ * character set, and lets me ask some questions that the * standard "ctype" macros cannot ask. */ -char cinfo[256] = { +const char cinfo[256] = { _C, _C, _C, _C, /* 0x0X */ _C, _C, _C, _C, _C, _C, _C, _C, @@ -90,9 +90,10 @@ char cinfo[256] = { * '\0'. */ char * -keyname(cp, k) - char *cp; - int k; +keyname(cp, len, k) + char *cp; + size_t len; + int k; { char *np; @@ -145,6 +146,5 @@ keyname(cp, k) *cp = '\0'; return cp; } - strcpy(cp, np); - return cp + strlen(cp); + return cp + strlcpy(cp, np, len); } diff --git a/usr.bin/mg/def.h b/usr.bin/mg/def.h index 3d775ba758f..a45f59d654d 100644 --- a/usr.bin/mg/def.h +++ b/usr.bin/mg/def.h @@ -1,4 +1,4 @@ -/* $OpenBSD: def.h,v 1.16 2001/05/23 22:20:35 art Exp $ */ +/* $OpenBSD: def.h,v 1.17 2001/05/23 23:29:47 mickey Exp $ */ /* * This file is the general header file for all parts @@ -412,7 +412,7 @@ int quit __P((int, int)); void panic __P((char *)); /* cinfo.c */ -char *keyname __P((char *, int)); +char *keyname __P((char *, size_t, int)); /* basic.c */ int gotobol __P((int, int)); @@ -574,12 +574,11 @@ extern int tthue; extern int nmaps; extern int defb_nmodes; extern int defb_flag; -extern char cinfo[]; +extern const char cinfo[]; extern char *keystrings[]; extern char pat[]; #ifndef NO_DPROMPT extern char prompt[]; -extern char *promptp; #endif /* !NO_DPROMPT */ /* diff --git a/usr.bin/mg/echo.c b/usr.bin/mg/echo.c index f357130cbe0..860e415eeab 100644 --- a/usr.bin/mg/echo.c +++ b/usr.bin/mg/echo.c @@ -1,4 +1,4 @@ -/* $OpenBSD: echo.c,v 1.11 2001/05/23 22:23:55 art Exp $ */ +/* $OpenBSD: echo.c,v 1.12 2001/05/23 23:29:47 mickey Exp $ */ /* * Echo line reading and writing. @@ -611,11 +611,10 @@ ewprintf(const char *fmt, ...) static void eformat(fp, ap) const char *fp; - va_list ap; + va_list ap; { - int c; - char kname[NKNAME]; - char *cp; + char kname[NKNAME], *cp; + int c; while ((c = *fp++) != '\0') { if (c != '%') @@ -624,17 +623,17 @@ eformat(fp, ap) c = *fp++; switch (c) { case 'c': - (void)keyname(kname, va_arg(ap, int)); + keyname(kname, sizeof(kname), va_arg(ap, int)); eputs(kname); break; case 'k': - cp = kname; - for (c = 0; c < key.k_count; c++) { - cp = keyname(cp, key.k_chars[c]); - *cp++ = ' '; + for (cp = kname, c = 0; c < key.k_count; c++) { + if (c) + *cp++ = ' '; + cp = keyname(cp, sizeof(kname) - + (cp - kname) - 1, key.k_chars[c]); } - *--cp = '\0'; eputs(kname); break; diff --git a/usr.bin/mg/extend.c b/usr.bin/mg/extend.c index ec83d3d9872..9a0723d4420 100644 --- a/usr.bin/mg/extend.c +++ b/usr.bin/mg/extend.c @@ -1,4 +1,4 @@ -/* $OpenBSD: extend.c,v 1.13 2001/05/23 22:36:13 art Exp $ */ +/* $OpenBSD: extend.c,v 1.14 2001/05/23 23:29:47 mickey Exp $ */ /* * Extended (M-X) commands, rebinding, and startup file processing. @@ -351,12 +351,12 @@ dobind(curmap, p, unbind) } else { #endif /* !NO_STARTUP */ #endif /* !NO_MACRO */ - (void)strcpy(prompt, p); - pep = prompt + strlen(prompt); + pep = prompt + strlcpy(prompt, p, sizeof(prompt)); for (;;) { ewprintf("%s", prompt); pep[-1] = ' '; - pep = keyname(pep, c = getkey(FALSE)); + pep = keyname(pep, sizeof(prompt) - (pep - prompt), + c = getkey(FALSE)); if (doscan(curmap, c, &curmap) != NULL) break; *pep++ = '-'; diff --git a/usr.bin/mg/help.c b/usr.bin/mg/help.c index 413482821ab..ffb4a9ff126 100644 --- a/usr.bin/mg/help.c +++ b/usr.bin/mg/help.c @@ -1,4 +1,4 @@ -/* $OpenBSD: help.c,v 1.10 2001/05/23 22:20:35 art Exp $ */ +/* $OpenBSD: help.c,v 1.11 2001/05/23 23:29:47 mickey Exp $ */ /* * Help functions for Mg 2 @@ -14,7 +14,7 @@ #endif /* !NO_MACRO */ static int showall(BUFFER *, KEYMAP *, char *); -static int findbind(KEYMAP *, PF, char *); +static int findbind(KEYMAP *, PF, char *, size_t); /* * Read a key from the keyboard, and look it up in the keymap. @@ -35,8 +35,7 @@ desckey(f, n) if (inmacro) return TRUE; /* ignore inside keyboard macro */ #endif /* !NO_MACRO */ - strcpy(prompt, "Describe key briefly: "); - pep = prompt + strlen(prompt); + pep = prompt + strlcpy(prompt, "Describe key briefly: ", sizeof(prompt)); key.k_count = 0; m = curbp->b_nmodes; curmap = curbp->b_modes[m]->p_map; @@ -44,8 +43,8 @@ desckey(f, n) for (;;) { ewprintf("%s", prompt); pep[-1] = ' '; - pep = keyname(pep, key.k_chars[key.k_count++] = - c = getkey(FALSE)); + pep = keyname(pep, sizeof(prompt) - (pep - prompt), + key.k_chars[key.k_count++] = c = getkey(FALSE)); if ((funct = doscan(curmap, c, &curmap)) != NULL) break; *pep++ = '-'; @@ -136,7 +135,7 @@ showall(BUFFER *bp, KEYMAP *map, char *prefix) fun = doscan(map, c, &newmap); if (fun == rescan || fun == selfinsert) continue; - keyname(buf, c); + keyname(buf, c, sizeof(buf)); sprintf(key, "%s%s ", prefix, buf); if (fun == NULL) { if (showall(bp, newmap, key) == FALSE) @@ -195,7 +194,8 @@ apropos_command(f, n) continue; buf[0] = '\0'; - findbind(fundamental_map, name_function(el->l_name), buf); + findbind(fundamental_map, name_function(el->l_name), + buf, sizeof(buf)); if (addlinef(bp, "%-32s%s", el->l_name, buf) == FALSE) { free_file_list(fnames); @@ -207,7 +207,7 @@ apropos_command(f, n) } static int -findbind(KEYMAP *map, PF fun, char *buf) +findbind(KEYMAP *map, PF fun, char *buf, size_t len) { KEYMAP *newmap; PF nfun; @@ -218,13 +218,13 @@ findbind(KEYMAP *map, PF fun, char *buf) for (c = 0; c < 256; c++) { nfun = doscan(map, c, &newmap); if (nfun == fun) { - keyname(buf, c); + keyname(buf, c, len); return TRUE; } if (nfun == NULL) { - if (findbind(newmap, fun, buf2) == TRUE) { - keyname(key, c); - sprintf(buf, "%s %s", key, buf2); + if (findbind(newmap, fun, buf2, sizeof(buf2)) == TRUE) { + keyname(key, c, sizeof(key)); + snprintf(buf, len, "%s %s", key, buf2); return TRUE; } } diff --git a/usr.bin/mg/kbd.c b/usr.bin/mg/kbd.c index 4d733cb0516..87772f9eebc 100644 --- a/usr.bin/mg/kbd.c +++ b/usr.bin/mg/kbd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kbd.c,v 1.8 2001/05/23 22:20:35 art Exp $ */ +/* $OpenBSD: kbd.c,v 1.9 2001/05/23 23:29:48 mickey Exp $ */ /* * Terminal independent keyboard handling. @@ -21,7 +21,7 @@ #ifndef NO_DPROMPT #define PROMPTL 80 -char prompt[PROMPTL], *promptp; +char prompt[PROMPTL] = "", *promptp = prompt; #endif /* !NO_DPROMPT */ static int use_metakey = TRUE; @@ -117,7 +117,8 @@ getkey(flag) #endif /* DO_METAKEY */ #ifndef NO_DPROMPT if (flag && promptp < &prompt[PROMPTL - 5]) { - promptp = keyname(promptp, c); + promptp = keyname(promptp, + sizeof(prompt) - (promptp - prompt) - 1, c); *promptp++ = '-'; *promptp = '\0'; } diff --git a/usr.bin/mg/main.c b/usr.bin/mg/main.c index f2a52185ec7..abd5c34cba0 100644 --- a/usr.bin/mg/main.c +++ b/usr.bin/mg/main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.8 2001/05/23 22:36:15 art Exp $ */ +/* $OpenBSD: main.c,v 1.9 2001/05/23 23:29:48 mickey Exp $ */ /* * Mainline. @@ -61,7 +61,6 @@ main(argc, argv) thisflag = 0; for (;;) { #ifndef NO_DPROMPT - *(promptp = prompt) = '\0'; if (epresf == KPROMPT) eerase(); #endif /* !NO_DPROMPT */ |