diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 1998-06-23 22:40:56 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 1998-06-23 22:40:56 +0000 |
commit | 30cb72a00b8cc59895c391cad0f8e31611611ec4 (patch) | |
tree | 3e2f67dd80af3489363cf0596b740c6533994e40 /usr.bin/vi | |
parent | 325437057bbda9490b174c8fc6dc8f0e14a8f145 (diff) |
Fix snprintf return value usage.
Diffstat (limited to 'usr.bin/vi')
-rw-r--r-- | usr.bin/vi/cl/cl_term.c | 2 | ||||
-rw-r--r-- | usr.bin/vi/common/api.c | 6 | ||||
-rw-r--r-- | usr.bin/vi/common/exf.c | 6 | ||||
-rw-r--r-- | usr.bin/vi/ex/ex_tag.c | 3 | ||||
-rw-r--r-- | usr.bin/vi/ex/ex_visual.c | 2 | ||||
-rw-r--r-- | usr.bin/vi/vi/v_at.c | 2 | ||||
-rw-r--r-- | usr.bin/vi/vi/v_increment.c | 4 | ||||
-rw-r--r-- | usr.bin/vi/vi/v_search.c | 4 | ||||
-rw-r--r-- | usr.bin/vi/vi/vs_line.c | 4 |
9 files changed, 31 insertions, 2 deletions
diff --git a/usr.bin/vi/cl/cl_term.c b/usr.bin/vi/cl/cl_term.c index 6edaffb0bf4..a86b9924b00 100644 --- a/usr.bin/vi/cl/cl_term.c +++ b/usr.bin/vi/cl/cl_term.c @@ -221,6 +221,8 @@ cl_pfmap(sp, stype, from, flen, to, tlen) nlen = snprintf(keyname, sizeof(keyname), "function key %d", atoi(from + 1)); + if (nlen >= sizeof(keyname)) + nlen = sizeof(keyname) - 1; return (seq_set(sp, keyname, nlen, p, strlen(p), to, tlen, stype, SEQ_NOOVERWRITE | SEQ_SCREEN)); } diff --git a/usr.bin/vi/common/api.c b/usr.bin/vi/common/api.c index 35d9f0c8f66..aac0ac627b3 100644 --- a/usr.bin/vi/common/api.c +++ b/usr.bin/vi/common/api.c @@ -488,14 +488,20 @@ api_opts_set(sp, name, str_value, num_value, bool_value) case OPT_1BOOL: GET_SPACE_RET(sp, bp, blen, 64); a.len = snprintf(bp, 64, "%s%s", bool_value ? "" : "no", name); + if (a.len > 63) + a.len = 63; break; case OPT_NUM: GET_SPACE_RET(sp, bp, blen, 64); a.len = snprintf(bp, 64, "%s=%lu", name, num_value); + if (a.len > 63) + a.len = 63; break; case OPT_STR: GET_SPACE_RET(sp, bp, blen, 1024); a.len = snprintf(bp, 1024, "%s=%s", name, str_value); + if (a.len > 63) + a.len = 63; break; } a.bp = bp; diff --git a/usr.bin/vi/common/exf.c b/usr.bin/vi/common/exf.c index 39c781a3f7d..574a16aab3b 100644 --- a/usr.bin/vi/common/exf.c +++ b/usr.bin/vi/common/exf.c @@ -482,6 +482,8 @@ file_spath(sp, frp, sbp, existsp) *p = '\0'; len = snprintf(path, sizeof(path), "%s/%s", t, name); + if (len >= sizeof(path)) + len = sizeof(path) - 1; *p = savech; if (!stat(path, sbp)) { found = 1; @@ -941,12 +943,16 @@ file_write(sp, fm, tm, name, flags) msgstr = msg_cat(sp, "256|%s: new file: %lu lines, %lu characters", NULL); len = snprintf(buf, sizeof(buf), msgstr, p, nlno, nch); + if (len >= sizeof(buf)) + len = sizeof(buf) - 1; break; case OLDFILE: msgstr = msg_cat(sp, LF_ISSET(FS_APPEND) ? "315|%s: appended: %lu lines, %lu characters" : "257|%s: %lu lines, %lu characters", NULL); len = snprintf(buf, sizeof(buf), msgstr, p, nlno, nch); + if (len >= sizeof(buf)) + len = sizeof(buf) - 1; break; default: abort(); diff --git a/usr.bin/vi/ex/ex_tag.c b/usr.bin/vi/ex/ex_tag.c index 63d80626a41..15aa58f4cc8 100644 --- a/usr.bin/vi/ex/ex_tag.c +++ b/usr.bin/vi/ex/ex_tag.c @@ -1181,7 +1181,6 @@ ctag_file(sp, tfp, name, dirp, dlenp) size_t *dlenp; { struct stat sb; - size_t len; char *p, buf[MAXPATHLEN]; /* @@ -1196,7 +1195,7 @@ ctag_file(sp, tfp, name, dirp, dlenp) if (name[0] != '/' && stat(name, &sb) && (p = strrchr(tfp->name, '/')) != NULL) { *p = '\0'; - len = snprintf(buf, sizeof(buf), "%s/%s", tfp->name, name); + (void)snprintf(buf, sizeof(buf), "%s/%s", tfp->name, name); if (stat(buf, &sb) == 0) { *dirp = tfp->name; *dlenp = strlen(*dirp); diff --git a/usr.bin/vi/ex/ex_visual.c b/usr.bin/vi/ex/ex_visual.c index 82e503d4465..c181f7709f4 100644 --- a/usr.bin/vi/ex/ex_visual.c +++ b/usr.bin/vi/ex/ex_visual.c @@ -84,6 +84,8 @@ ex_visual(sp, cmdp) "%luz%c%lu", sp->lno, pos, cmdp->count); else len = snprintf(buf, sizeof(buf), "%luz%c", sp->lno, pos); + if (len >= sizeof(buf)) + len = sizeof(buf) - 1; (void)v_event_push(sp, NULL, buf, len, CH_NOMAP | CH_QUOTED); /* diff --git a/usr.bin/vi/vi/v_at.c b/usr.bin/vi/vi/v_at.c index d266f275d98..7231bb1b674 100644 --- a/usr.bin/vi/vi/v_at.c +++ b/usr.bin/vi/vi/v_at.c @@ -102,6 +102,8 @@ v_at(sp, vp) */ if (F_ISSET(vp, VC_C1SET)) { len = snprintf(nbuf, sizeof(nbuf), "%lu", vp->count); + if (len >= sizeof(nbuf)) + len = sizeof(nbuf) - 1; if (v_event_push(sp, NULL, nbuf, len, 0)) return (1); } diff --git a/usr.bin/vi/vi/v_increment.c b/usr.bin/vi/vi/v_increment.c index 45e763fa5bd..370143187c6 100644 --- a/usr.bin/vi/vi/v_increment.c +++ b/usr.bin/vi/vi/v_increment.c @@ -204,6 +204,8 @@ nonum: msgq(sp, M_ERR, "181|Cursor not in a number"); if (lval == 0 && ntype == fmt[SDEC]) ntype = fmt[DEC]; nlen = snprintf(nbuf, sizeof(nbuf), ntype, lval); + if (nlen >= sizeof(nbuf)) + nlen = sizeof(nbuf) - 1; } else { if ((nret = nget_uslong(&ulval, t, NULL, base)) != NUM_OK) goto err; @@ -226,6 +228,8 @@ nonum: msgq(sp, M_ERR, "181|Cursor not in a number"); wlen -= 2; nlen = snprintf(nbuf, sizeof(nbuf), ntype, wlen, ulval); + if (nlen >= sizeof(nbuf)) + nlen = sizeof(nbuf) - 1; } /* Build the new line. */ diff --git a/usr.bin/vi/vi/v_search.c b/usr.bin/vi/vi/v_search.c index 4f7a2671ab8..6851a93fa5b 100644 --- a/usr.bin/vi/vi/v_search.c +++ b/usr.bin/vi/vi/v_search.c @@ -255,6 +255,8 @@ v_exaddr(sp, vp, dir) /* Push line number so get correct z display. */ tlen = snprintf(buf, sizeof(buf), "%lu", (u_long)vp->m_stop.lno); + if (tlen >= sizeof(buf)) + tlen = sizeof(buf) - 1; if (v_event_push(sp, NULL, buf, tlen, CH_NOMAP | CH_QUOTED)) return (1); @@ -336,6 +338,8 @@ v_searchw(sp, vp) len = VIP(sp)->klen + sizeof(RE_WSTART) + sizeof(RE_WSTOP); GET_SPACE_RET(sp, bp, blen, len); len = snprintf(bp, blen, "%s%s%s", RE_WSTART, VIP(sp)->keyw, RE_WSTOP); + if (len >= blen) + len = blen - 1; rval = v_search(sp, vp, bp, len, SEARCH_SET, FORWARD); diff --git a/usr.bin/vi/vi/vs_line.c b/usr.bin/vi/vi/vs_line.c index b439de925ce..a8a65c0d3ca 100644 --- a/usr.bin/vi/vi/vs_line.c +++ b/usr.bin/vi/vi/vs_line.c @@ -140,6 +140,8 @@ vs_line(sp, smp, yp, xp) if ((!dne || smp->lno == 1) && skip_cols == 0) { nlen = snprintf(cbuf, sizeof(cbuf), O_NUMBER_FMT, smp->lno); + if (nlen >= sizeof(cbuf)) + nlen = sizeof(cbuf) - 1; (void)gp->scr_addstr(sp, cbuf, nlen); } } @@ -507,6 +509,8 @@ vs_number(sp) (void)gp->scr_move(sp, smp - HMAP, 0); len = snprintf(nbuf, sizeof(nbuf), O_NUMBER_FMT, smp->lno); + if (len >= sizeof(nbuf)) + len = sizeof(nbuf) - 1; (void)gp->scr_addstr(sp, nbuf, len); } (void)gp->scr_move(sp, oldy, oldx); |