CVS commit: src/usr.bin/xlint/lint2
Module Name:src Committed By: rillig Date: Wed Aug 11 05:37:45 UTC 2021 Modified Files: src/usr.bin/xlint/lint2: main2.c Log Message: lint: add reminder to sort the output of lint2 To generate a diff of this commit: cvs rdiff -u -r1.17 -r1.18 src/usr.bin/xlint/lint2/main2.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/xlint/lint2/main2.c diff -u src/usr.bin/xlint/lint2/main2.c:1.17 src/usr.bin/xlint/lint2/main2.c:1.18 --- src/usr.bin/xlint/lint2/main2.c:1.17 Sun Apr 18 22:51:24 2021 +++ src/usr.bin/xlint/lint2/main2.c Wed Aug 11 05:37:45 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: main2.c,v 1.17 2021/04/18 22:51:24 rillig Exp $ */ +/* $NetBSD: main2.c,v 1.18 2021/08/11 05:37:45 rillig Exp $ */ /* * Copyright (c) 1994, 1995 Jochen Pohl @@ -37,7 +37,7 @@ #include #if defined(__RCSID) && !defined(lint) -__RCSID("$NetBSD: main2.c,v 1.17 2021/04/18 22:51:24 rillig Exp $"); +__RCSID("$NetBSD: main2.c,v 1.18 2021/08/11 05:37:45 rillig Exp $"); #endif #include @@ -181,6 +181,7 @@ main(int argc, char *argv[]) mainused(); /* perform all tests */ + /* TODO: sort the names; hashcode order looks chaotic. */ forall(chkname); exit(0);
CVS commit: src/usr.bin/xlint/lint2
Module Name:src Committed By: rillig Date: Sun Aug 8 11:56:36 UTC 2021 Modified Files: src/usr.bin/xlint/lint2: Makefile chk.c read.c Log Message: lint: force strict bool mode No functional change. To generate a diff of this commit: cvs rdiff -u -r1.20 -r1.21 src/usr.bin/xlint/lint2/Makefile cvs rdiff -u -r1.42 -r1.43 src/usr.bin/xlint/lint2/chk.c cvs rdiff -u -r1.48 -r1.49 src/usr.bin/xlint/lint2/read.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/xlint/lint2/Makefile diff -u src/usr.bin/xlint/lint2/Makefile:1.20 src/usr.bin/xlint/lint2/Makefile:1.21 --- src/usr.bin/xlint/lint2/Makefile:1.20 Sun Apr 18 22:51:24 2021 +++ src/usr.bin/xlint/lint2/Makefile Sun Aug 8 11:56:35 2021 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.20 2021/04/18 22:51:24 rillig Exp $ +# $NetBSD: Makefile,v 1.21 2021/08/08 11:56:35 rillig Exp $ NOMAN= # defined @@ -7,6 +7,7 @@ SRCS= main2.c hash.c read.c mem.c mem2. inittyp.c tyname.c BINDIR= /usr/libexec CPPFLAGS+= -I${.CURDIR} +LINTFLAGS+= -T # strict bool mode COPTS.msg.c+= ${${ACTIVE_CC} == "clang":? -Wno-format-nonliteral :} Index: src/usr.bin/xlint/lint2/chk.c diff -u src/usr.bin/xlint/lint2/chk.c:1.42 src/usr.bin/xlint/lint2/chk.c:1.43 --- src/usr.bin/xlint/lint2/chk.c:1.42 Fri Apr 2 12:16:50 2021 +++ src/usr.bin/xlint/lint2/chk.c Sun Aug 8 11:56:35 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: chk.c,v 1.42 2021/04/02 12:16:50 rillig Exp $ */ +/* $NetBSD: chk.c,v 1.43 2021/08/08 11:56:35 rillig Exp $ */ /* * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. @@ -38,7 +38,7 @@ #include #if defined(__RCSID) && !defined(lint) -__RCSID("$NetBSD: chk.c,v 1.42 2021/04/02 12:16:50 rillig Exp $"); +__RCSID("$NetBSD: chk.c,v 1.43 2021/08/08 11:56:35 rillig Exp $"); #endif #include @@ -1085,9 +1085,9 @@ chkrvu(hte_t *hte, sym_t *def) * but for now I don't want to be bothered by this warnings * which are almost always useless. */ - if (hflag == 0) + if (!hflag) return; - if (hflag == 1 && bsearch(hte->h_name, ignorelist, + if (hflag && bsearch(hte->h_name, ignorelist, __arraycount(ignorelist), sizeof(ignorelist[0]), (int (*)(const void *, const void *))strcmp) != NULL) return; @@ -1340,7 +1340,7 @@ eqargs(type_t *tp1, type_t *tp2, bool *d while (*a1 != NULL && *a2 != NULL) { - if (eqtype(*a1, *a2, true, false, false, dowarn) == 0) + if (!eqtype(*a1, *a2, true, false, false, dowarn)) return false; a1++; Index: src/usr.bin/xlint/lint2/read.c diff -u src/usr.bin/xlint/lint2/read.c:1.48 src/usr.bin/xlint/lint2/read.c:1.49 --- src/usr.bin/xlint/lint2/read.c:1.48 Thu Aug 5 06:54:16 2021 +++ src/usr.bin/xlint/lint2/read.c Sun Aug 8 11:56:35 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: read.c,v 1.48 2021/08/05 06:54:16 rillig Exp $ */ +/* $NetBSD: read.c,v 1.49 2021/08/08 11:56:35 rillig Exp $ */ /* * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. @@ -38,7 +38,7 @@ #include #if defined(__RCSID) && !defined(lint) -__RCSID("$NetBSD: read.c,v 1.48 2021/08/05 06:54:16 rillig Exp $"); +__RCSID("$NetBSD: read.c,v 1.49 2021/08/08 11:56:35 rillig Exp $"); #endif #include @@ -402,7 +402,7 @@ decldef(pos_t *posp, const char *cp) sym.s_def = DECL; break; case 'i': - if (sym.s_inline != NODECL) + if (sym.s_inline) inperr("inline %c", c); sym.s_inline = true; break;
CVS commit: src/usr.bin/xlint/lint2
Module Name:src Committed By: rillig Date: Thu Aug 5 06:54:16 UTC 2021 Modified Files: src/usr.bin/xlint/lint2: read.c Log Message: lint: fix type of local variable in inpqstrg Noted by Clang-Tidy. To generate a diff of this commit: cvs rdiff -u -r1.47 -r1.48 src/usr.bin/xlint/lint2/read.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/xlint/lint2/read.c diff -u src/usr.bin/xlint/lint2/read.c:1.47 src/usr.bin/xlint/lint2/read.c:1.48 --- src/usr.bin/xlint/lint2/read.c:1.47 Thu Aug 5 06:45:37 2021 +++ src/usr.bin/xlint/lint2/read.c Thu Aug 5 06:54:16 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: read.c,v 1.47 2021/08/05 06:45:37 rillig Exp $ */ +/* $NetBSD: read.c,v 1.48 2021/08/05 06:54:16 rillig Exp $ */ /* * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. @@ -38,7 +38,7 @@ #include #if defined(__RCSID) && !defined(lint) -__RCSID("$NetBSD: read.c,v 1.47 2021/08/05 06:45:37 rillig Exp $"); +__RCSID("$NetBSD: read.c,v 1.48 2021/08/05 06:54:16 rillig Exp $"); #endif #include @@ -1057,7 +1057,7 @@ inpqstrg(const char *src, const char **e { char *strg, *dst; size_t slen; - int c; + char c; int v; dst = strg = xmalloc(slen = 32); @@ -1110,7 +1110,7 @@ inpqstrg(const char *src, const char **e if ((c = *src++) < '0' || c > '7') inperr("not octal: %c", c); v |= c - '0'; -c = (u_char)v; +c = (char)v; break; default: inperr("bad \\ escape: %c", c); @@ -1122,7 +1122,7 @@ inpqstrg(const char *src, const char **e dst = strg + (slen - 1); slen *= 2; } - *dst++ = (char)c; + *dst++ = c; if ((c = *src++) == '\0') inperr("missing closing quote"); }
CVS commit: src/usr.bin/xlint/lint2
Module Name:src Committed By: rillig Date: Thu Aug 5 06:45:37 UTC 2021 Modified Files: src/usr.bin/xlint/lint2: read.c Log Message: lint: fix handling of __int128_t/__uint128_t in lint2 Previously, lint exited with "bad type: J u". To generate a diff of this commit: cvs rdiff -u -r1.46 -r1.47 src/usr.bin/xlint/lint2/read.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/xlint/lint2/read.c diff -u src/usr.bin/xlint/lint2/read.c:1.46 src/usr.bin/xlint/lint2/read.c:1.47 --- src/usr.bin/xlint/lint2/read.c:1.46 Sat Jul 31 19:52:44 2021 +++ src/usr.bin/xlint/lint2/read.c Thu Aug 5 06:45:37 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: read.c,v 1.46 2021/07/31 19:52:44 rillig Exp $ */ +/* $NetBSD: read.c,v 1.47 2021/08/05 06:45:37 rillig Exp $ */ /* * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. @@ -38,7 +38,7 @@ #include #if defined(__RCSID) && !defined(lint) -__RCSID("$NetBSD: read.c,v 1.46 2021/07/31 19:52:44 rillig Exp $"); +__RCSID("$NetBSD: read.c,v 1.47 2021/08/05 06:45:37 rillig Exp $"); #endif #include @@ -838,6 +838,15 @@ gettlen(const char *cp, const char **epp t = QUAD; } break; +#ifdef INT128_SIZE + case 'J': + if (s == 'u') { + t = UINT128; + } else if (s == '\0') { + t = INT128; + } + break; +#endif case 'D': if (s == 's') { t = FLOAT;
CVS commit: src/usr.bin/xlint/lint2
Module Name:src Committed By: rillig Date: Sun Apr 18 21:12:51 UTC 2021 Modified Files: src/usr.bin/xlint/lint2: read.c Log Message: lint: reduce duplicate code for parsing .ln files To generate a diff of this commit: cvs rdiff -u -r1.43 -r1.44 src/usr.bin/xlint/lint2/read.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/xlint/lint2/read.c diff -u src/usr.bin/xlint/lint2/read.c:1.43 src/usr.bin/xlint/lint2/read.c:1.44 --- src/usr.bin/xlint/lint2/read.c:1.43 Sun Apr 18 20:40:51 2021 +++ src/usr.bin/xlint/lint2/read.c Sun Apr 18 21:12:50 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: read.c,v 1.43 2021/04/18 20:40:51 rillig Exp $ */ +/* $NetBSD: read.c,v 1.44 2021/04/18 21:12:50 rillig Exp $ */ /* * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. @@ -38,7 +38,7 @@ #include #if defined(__RCSID) && !defined(lint) -__RCSID("$NetBSD: read.c,v 1.43 2021/04/18 20:40:51 rillig Exp $"); +__RCSID("$NetBSD: read.c,v 1.44 2021/04/18 21:12:50 rillig Exp $"); #endif #include @@ -108,13 +108,45 @@ static char *inpqstrg(const char *, cons static const char *inpname(const char *, const char **); static int getfnidx(const char *); +static bool +try_parse_int(const char **p, int *num) +{ + char *end; + + *num = (int)strtol(*p, , 10); + if (end == *p) + return false; + *p = end; + return true; +} + +static int +parse_int(const char **p) +{ + char *end; + int n; + + n = (int)strtol(*p, , 10); + if (end == *p) + inperr("not a number: %s", *p); + *p = end; + return n; +} + +static short +parse_short(const char **p) +{ + + return (short)parse_int(p); +} + void readfile(const char *name) { FILE *inp; size_t len; const char *cp; - char *line, *eptr, rt = '\0'; + char *line, rt = '\0'; int cline, isrc, iline; pos_t pos; @@ -145,12 +177,8 @@ readfile(const char *name) cp = line; /* line number in csrcfile */ - cline = (int)strtol(cp, , 10); - if (cp == eptr) { - cline = -1; - } else { - cp = eptr; - } + if (!try_parse_int(, )) + cline = -1; /* record type */ if (*cp == '\0') @@ -170,19 +198,13 @@ readfile(const char *name) * different from csrcfile, it refers to an included * file. */ - isrc = (int)strtol(cp, , 10); - if (cp == eptr) - inperr("not a number: %s", cp); - cp = eptr; + isrc = parse_int(); isrc = inpfns[isrc]; /* line number in isrc */ if (*cp++ != '.') inperr("bad line number"); - iline = (int)strtol(cp, , 10); - if (cp == eptr) - inperr("not a number: %s", cp); - cp = eptr; + iline = parse_int(); pos.p_src = (u_short)csrcfile; pos.p_line = (u_short)cline; @@ -274,7 +296,7 @@ static void funccall(pos_t *posp, const char *cp) { arginf_t *ai, **lai; - char c, *eptr; + char c; bool rused, rdisc; hte_t *hte; fcall_t *fcall; @@ -309,10 +331,7 @@ funccall(pos_t *posp, const char *cp) case 'n': case 's': ai = xalloc(sizeof(*ai)); - ai->a_num = (int)strtol(cp, , 10); - if (cp == eptr) -inperr("bad number: %s", cp); - cp = eptr; + ai->a_num = parse_int(); if (c == 'z') { ai->a_pcon = ai->a_zero = true; } else if (c == 'p') { @@ -358,7 +377,7 @@ static void decldef(pos_t *posp, const char *cp) { sym_t *symp, sym; - char c, *ep, *pos1, *tname; + char c, *pos1, *tname; bool used, renamed; hte_t *hte, *renamehte = NULL; const char *name, *newname; @@ -416,28 +435,19 @@ decldef(pos_t *posp, const char *cp) if (sym.s_va) inperr("va"); sym.s_va = true; - sym.s_nva = (short)strtol(cp, , 10); - if (cp == ep) -inperr("bad number: %s", cp); - cp = ep; + sym.s_nva = parse_short(); break; case 'P': if (sym.s_prfl) inperr("prfl"); sym.s_prfl = true; - sym.s_nprfl = (short)strtol(cp, , 10); - if (cp == ep) -inperr("bad number: %s", cp); - cp = ep; + sym.s_nprfl = parse_short(); break; case 'S': if (sym.s_scfl) inperr("scfl"); sym.s_scfl = true; - sym.s_nscfl = (short)strtol(cp, , 10); - if (cp == ep) -inperr("bad number: %s", cp); - cp = ep; + sym.s_nscfl = parse_short(); break; } } @@ -552,7 +562,7 @@ usedsym(pos_t *posp, const char *cp) static u_short inptype(const char *cp, const char **epp) { - char c, s, *eptr; + char c, s; const char *ep; type_t *tp; int narg, i; @@ -645,8 +655,7 @@ inptype(const char *cp, const char **epp switch (tp->t_tspec) { case ARRAY: - tp->t_dim = (int)strtol(cp, , 10); - cp = eptr; + tp->t_dim = parse_int(); sidx = inptype(cp, ); /* force seq. point! (ditto below) */ tp->t_subt = TP(sidx); break; @@ -659,8 +668,7 @@ inptype(const char *cp, const char **epp if (ch_isdigit(c)) { if (!osdef) tp->t_proto = true; - narg = (int)strtol(cp, , 10); - cp = eptr; + narg = parse_int(); tp->t_args = xcalloc((size_t)(narg + 1), sizeof(*tp->t_args)); for (i = 0; i <
CVS commit: src/usr.bin/xlint/lint2
Module Name:src Committed By: rillig Date: Sun Apr 18 20:40:51 UTC 2021 Modified Files: src/usr.bin/xlint/lint2: read.c Log Message: lint: fix error message in lint2 for missing record type in .ln file To generate a diff of this commit: cvs rdiff -u -r1.42 -r1.43 src/usr.bin/xlint/lint2/read.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/xlint/lint2/read.c diff -u src/usr.bin/xlint/lint2/read.c:1.42 src/usr.bin/xlint/lint2/read.c:1.43 --- src/usr.bin/xlint/lint2/read.c:1.42 Fri Apr 2 12:16:50 2021 +++ src/usr.bin/xlint/lint2/read.c Sun Apr 18 20:40:51 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: read.c,v 1.42 2021/04/02 12:16:50 rillig Exp $ */ +/* $NetBSD: read.c,v 1.43 2021/04/18 20:40:51 rillig Exp $ */ /* * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. @@ -38,7 +38,7 @@ #include #if defined(__RCSID) && !defined(lint) -__RCSID("$NetBSD: read.c,v 1.42 2021/04/02 12:16:50 rillig Exp $"); +__RCSID("$NetBSD: read.c,v 1.43 2021/04/18 20:40:51 rillig Exp $"); #endif #include @@ -153,11 +153,9 @@ readfile(const char *name) } /* record type */ - if (*cp != '\0') { - rt = *cp++; - } else { - inperr("null cp"); - } + if (*cp == '\0') + inperr("missing record type"); + rt = *cp++; if (rt == 'S') { setsrc(cp);
CVS commit: src/usr.bin/xlint/lint2
Module Name:src Committed By: rillig Date: Sun Feb 28 18:17:08 UTC 2021 Added Files: src/usr.bin/xlint/lint2: check-msgs.lua Log Message: lint2: add redundancy checker for comments in source code Based on the redundancy checker for lint1. No functional change. To generate a diff of this commit: cvs rdiff -u -r0 -r1.1 src/usr.bin/xlint/lint2/check-msgs.lua Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Added files: Index: src/usr.bin/xlint/lint2/check-msgs.lua diff -u /dev/null src/usr.bin/xlint/lint2/check-msgs.lua:1.1 --- /dev/null Sun Feb 28 18:17:08 2021 +++ src/usr.bin/xlint/lint2/check-msgs.lua Sun Feb 28 18:17:08 2021 @@ -0,0 +1,110 @@ +#! /usr/bin/lua +-- $NetBSD: check-msgs.lua,v 1.1 2021/02/28 18:17:08 rillig Exp $ + +--[[ + +usage: lua ./check-msgs.lua *.c + +Check that the message text in the comments of the C source code matches the +actual user-visible message text in msg.c. + +]] + + +local function load_messages(fname) + local msgs = {} + + local f = assert(io.open(fname, "r")) + for line in f:lines() do +local msg, id = line:match("%s*\"(.+)\",%s*/%*%s*(%d+)%s*%*/$") +if msg ~= nil then + msgs[tonumber(id)] = msg +end + end + + f:close() + + return msgs +end + + +local function check_message(fname, lineno, id, comment, msgs, errors) + local msg = msgs[id] + + if msg == nil then +errors:add("%s:%d: id=%d not found", fname, lineno, id) +return + end + + msg = msg:gsub("/%*", "**") + msg = msg:gsub("%*/", "**") + msg = msg:gsub("\\t", "t") -- for lint2 + msg = msg:gsub("\\(.)", "%1") + + if comment == msg then +return + end + + local prefix = comment:match("^(.-)%s*%.%.%.$") + if prefix ~= nil and msg:find(prefix, 1, 1) == 1 then +return + end + + errors:add("%s:%d: id=%-3d msg=%-40s comment=%s", +fname, lineno, id, msg, comment) +end + + +local function collect_errors(fname, msgs) + local errors = {} + errors.add = function(self, fmt, ...) +table.insert(self, fmt:format(...)) + end + + local f = assert(io.open(fname, "r")) + local lineno = 0 + local prev = "" + for line in f:lines() do +lineno = lineno + 1 + +local func, id = line:match("^%s+(%w+)%((%d+)[),]") +id = tonumber(id) +if func == "msg" then + local comment = prev:match("^%s+/%* (.+) %*/$") + if comment ~= nil then +check_message(fname, lineno, id, comment, msgs, errors) + else +errors:add("%s:%d: missing comment for %d: /* %s */", + fname, lineno, id, msgs[id]) + end +end + +prev = line + end + + f:close() + + return errors +end + + +local function check_file(fname, msgs) + local errors = collect_errors(fname, msgs) + for _, err in ipairs(errors) do +print(err) + end + return #errors == 0 +end + + +local function main(arg) + local msgs = load_messages("msg.c") + local ok = true + for _, fname in ipairs(arg) do +ok = check_file(fname, msgs) and ok + end + return ok +end + + +os.exit(main(arg))
CVS commit: src/usr.bin/xlint/lint2
Module Name:src Committed By: rillig Date: Sun Feb 28 17:16:51 UTC 2021 Modified Files: src/usr.bin/xlint/lint2: chk.c read.c Log Message: lint2: align comments in the code with actual messages To generate a diff of this commit: cvs rdiff -u -r1.39 -r1.40 src/usr.bin/xlint/lint2/chk.c \ src/usr.bin/xlint/lint2/read.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/xlint/lint2/chk.c diff -u src/usr.bin/xlint/lint2/chk.c:1.39 src/usr.bin/xlint/lint2/chk.c:1.40 --- src/usr.bin/xlint/lint2/chk.c:1.39 Mon Feb 22 15:09:50 2021 +++ src/usr.bin/xlint/lint2/chk.c Sun Feb 28 17:16:50 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: chk.c,v 1.39 2021/02/22 15:09:50 rillig Exp $ */ +/* $NetBSD: chk.c,v 1.40 2021/02/28 17:16:50 rillig Exp $ */ /* * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. @@ -38,7 +38,7 @@ #include #if defined(__RCSID) && !defined(lint) -__RCSID("$NetBSD: chk.c,v 1.39 2021/02/22 15:09:50 rillig Exp $"); +__RCSID("$NetBSD: chk.c,v 1.40 2021/02/28 17:16:50 rillig Exp $"); #endif #include @@ -218,7 +218,7 @@ chkmd(hte_t *hte) continue; } pos1 = xstrdup(mkpos(>s_pos)); - /* %s multiply defined\t%s :: %s */ + /* %s multiply defined \t%s :: %s */ msg(3, hte->h_name, pos1, mkpos(>s_pos)); free(pos1); } @@ -273,7 +273,7 @@ chkvtui(hte_t *hte, sym_t *def, sym_t *d * accepted for now. */ pos1 = xstrdup(mkpos(>s_pos)); -/* %s value must be decl. before use %s :: %s */ +/* %s function value must be declared ... */ msg(17, hte->h_name, pos1, mkpos(>f_pos)); free(pos1); @@ -282,7 +282,7 @@ chkvtui(hte_t *hte, sym_t *def, sym_t *d } if (!eq || (sflag && dowarn)) { pos1 = xstrdup(mkpos(>s_pos)); - /* %s value used inconsistently\t%s :: %s */ + /* %s value used inconsistently \t%s :: %s */ msg(4, hte->h_name, pos1, mkpos(>f_pos)); free(pos1); } @@ -323,7 +323,7 @@ chkvtdi(hte_t *hte, sym_t *def, sym_t *d } if (!eq || (sflag && dowarn)) { pos1 = xstrdup(mkpos(>s_pos)); - /* %s value declared inconsistently\t%s :: %s */ + /* %s value declared inconsistently (%s != %s) \t... */ msg(5, hte->h_name, type_name(xt1), type_name(xt2), pos1, mkpos(>s_pos)); free(pos1); @@ -406,7 +406,7 @@ chkfaui(hte_t *hte, sym_t *def, sym_t *d */ } else { pos1 = xstrdup(mkpos(pos1p)); - /* %s: variable # of args\t%s :: %s */ + /* %s: variable # of args \t%s :: %s */ msg(7, hte->h_name, pos1, mkpos(>f_pos)); free(pos1); continue; @@ -589,7 +589,7 @@ chkau(hte_t *hte, int n, sym_t *def, sym } pos1 = xstrdup(mkpos(pos1p)); - /* %s, arg %d used inconsistently\t%s[%s] :: %s[%s] */ + /* %s, arg %d used inconsistently \t%s[%s] :: %s[%s] */ msg(6, hte->h_name, n, pos1, type_name(arg1), mkpos(>f_pos), type_name(arg2)); free(pos1); @@ -1019,7 +1019,7 @@ static void badfmt(hte_t *hte, fcall_t *call) { - /* %s: malformed format string\t%s */ + /* %s: malformed format string \t%s */ msg(13, hte->h_name, mkpos(>f_pos)); } @@ -1027,7 +1027,7 @@ static void inconarg(hte_t *hte, fcall_t *call, int n) { - /* %s, arg %d inconsistent with format\t%s(%d) */ + /* %s, arg %d inconsistent with format \t%s */ msg(14, hte->h_name, n, mkpos(>f_pos)); } @@ -1102,14 +1102,14 @@ chkrvu(hte_t *hte, sym_t *def) /* %s returns value which is always ignored */ msg(8, hte->h_name); } else if (used && ignored) { - /* %s returns value which is sometimes ign. */ + /* %s returns value which is sometimes ignored */ msg(9, hte->h_name); } } else { /* function has no return value */ for (call = hte->h_calls; call != NULL; call = call->f_next) { if (call->f_rused) -/* %s value is used( %s ), but none ret. */ +/* %s value is used( %s ), but none returned */ msg(10, hte->h_name, mkpos(>f_pos)); } } @@ -1178,8 +1178,8 @@ chkadecl(hte_t *hte, sym_t *def, sym_t * continue; } } - /* %s: variable # of args declared\t%s :: %s */ pos1 = xstrdup(mkpos(>s_pos)); + /* %s: variable # of args declared \t%s :: %s */ msg(12, hte->h_name, pos1, mkpos(>s_pos)); free(pos1); } Index: src/usr.bin/xlint/lint2/read.c diff -u src/usr.bin/xlint/lint2/read.c:1.39 src/usr.bin/xlint/lint2/read.c:1.40 --- src/usr.bin/xlint/lint2/read.c:1.39 Fri Feb 19 22:27:49 2021 +++ src/usr.bin/xlint/lint2/read.c Sun Feb 28 17:16:50 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: read.c,v 1.39 2021/02/19 22:27:49 rillig Exp $ */ +/* $NetBSD: read.c,v 1.40 2021/02/28 17:16:50 rillig Exp $ */ /* * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. @@ -38,7 +38,7 @@ #include #if defined(__RCSID) && !defined(lint) -__RCSID("$NetBSD: read.c,v 1.39 2021/02/19 22:27:49 rillig Exp $"); +__RCSID("$NetBSD: read.c,v 1.40 2021/02/28 17:16:50 rillig Exp $"); #endif #include @@ -461,7
CVS commit: src/usr.bin/xlint/lint2
Module Name:src Committed By: rillig Date: Sat Jan 16 00:09:28 UTC 2021 Modified Files: src/usr.bin/xlint/lint2: Makefile Log Message: lint: fix LINTFLAGS for lint2 These have never worked since they report a syntax error in just because there is an __inline over there. I wonder why it has been necessary at all to have custom LINTFLAGS for lint itself. It's just an ordinary program. To generate a diff of this commit: cvs rdiff -u -r1.17 -r1.18 src/usr.bin/xlint/lint2/Makefile Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/xlint/lint2/Makefile diff -u src/usr.bin/xlint/lint2/Makefile:1.17 src/usr.bin/xlint/lint2/Makefile:1.18 --- src/usr.bin/xlint/lint2/Makefile:1.17 Sun Oct 8 17:52:29 2006 +++ src/usr.bin/xlint/lint2/Makefile Sat Jan 16 00:09:28 2021 @@ -1,11 +1,10 @@ -# $NetBSD: Makefile,v 1.17 2006/10/08 17:52:29 peter Exp $ +# $NetBSD: Makefile,v 1.18 2021/01/16 00:09:28 rillig Exp $ NOMAN= # defined PROG= lint2 SRCS= main2.c hash.c read.c mem.c mem2.c chk.c msg.c emit.c emit2.c \ inittyp.c tyname.c -LINTFLAGS= -abehrz BINDIR= /usr/libexec CPPFLAGS+= -DPASS=\"${PROG}.h\" -I${.CURDIR}
CVS commit: src/usr.bin/xlint/lint2
Module Name:src Committed By: christos Date: Thu Jan 14 16:58:27 UTC 2010 Modified Files: src/usr.bin/xlint/lint2: chk.c main2.c Log Message: Add a list of functions where we usually don't care about their return code. Can be bypassed by -hh To generate a diff of this commit: cvs rdiff -u -r1.20 -r1.21 src/usr.bin/xlint/lint2/chk.c cvs rdiff -u -r1.7 -r1.8 src/usr.bin/xlint/lint2/main2.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/xlint/lint2/chk.c diff -u src/usr.bin/xlint/lint2/chk.c:1.20 src/usr.bin/xlint/lint2/chk.c:1.21 --- src/usr.bin/xlint/lint2/chk.c:1.20 Tue Apr 14 05:03:45 2009 +++ src/usr.bin/xlint/lint2/chk.c Thu Jan 14 11:58:27 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: chk.c,v 1.20 2009/04/14 09:03:45 lukem Exp $ */ +/* $NetBSD: chk.c,v 1.21 2010/01/14 16:58:27 christos Exp $ */ /* * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. @@ -38,10 +38,11 @@ #include sys/cdefs.h #if defined(__RCSID) !defined(lint) -__RCSID($NetBSD: chk.c,v 1.20 2009/04/14 09:03:45 lukem Exp $); +__RCSID($NetBSD: chk.c,v 1.21 2010/01/14 16:58:27 christos Exp $); #endif #include ctype.h +#include string.h #include limits.h #include stdlib.h @@ -1045,6 +1046,19 @@ msg(16, hte-h_name, mkpos(call-f_pos)); } +/* + * List of functions where we usually don't care about their result. + * NB: Must be sorted. + */ +static const char ignorelist[][8] = { + memcpy, + memmove, + memset, + printf, + strcat, + strcpy, + vprintf, +}; /* * Print warnings for return values which are used, but not returned, @@ -1064,26 +1078,31 @@ return; if (def-s_rval) { - /* function has return value */ - used = ignored = 0; - for (call = hte-h_calls; call != NULL; call = call-f_nxt) { - used |= call-f_rused || call-f_rdisc; - ignored |= !call-f_rused !call-f_rdisc; - } /* * XXX as soon as we are able to disable single warnings * the following dependencies from hflag should be removed. * but for now I do'nt want to be botherd by this warnings * which are almost always useless. */ + if (hflag == 0) + return; + if (hflag == 1 bsearch(hte-h_name, ignorelist, + __arraycount(ignorelist), sizeof(ignorelist[0]), + (int (*)(const void *, const void *))strcmp) != NULL) + return; + + /* function has return value */ + used = ignored = 0; + for (call = hte-h_calls; call != NULL; call = call-f_nxt) { + used |= call-f_rused || call-f_rdisc; + ignored |= !call-f_rused !call-f_rdisc; + } if (!used ignored) { - if (hflag) -/* %s returns value which is always ignored */ -msg(8, hte-h_name); + /* %s returns value which is always ignored */ + msg(8, hte-h_name); } else if (used ignored) { - if (hflag) -/* %s returns value which is sometimes ign. */ -msg(9, hte-h_name); + /* %s returns value which is sometimes ign. */ + msg(9, hte-h_name); } } else { /* function has no return value */ Index: src/usr.bin/xlint/lint2/main2.c diff -u src/usr.bin/xlint/lint2/main2.c:1.7 src/usr.bin/xlint/lint2/main2.c:1.8 --- src/usr.bin/xlint/lint2/main2.c:1.7 Sun Jun 20 18:20:17 2004 +++ src/usr.bin/xlint/lint2/main2.c Thu Jan 14 11:58:27 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: main2.c,v 1.7 2004/06/20 22:20:17 jmc Exp $ */ +/* $NetBSD: main2.c,v 1.8 2010/01/14 16:58:27 christos Exp $ */ /* * Copyright (c) 1994, 1995 Jochen Pohl @@ -37,7 +37,7 @@ #include sys/cdefs.h #if defined(__RCSID) !defined(lint) -__RCSID($NetBSD: main2.c,v 1.7 2004/06/20 22:20:17 jmc Exp $); +__RCSID($NetBSD: main2.c,v 1.8 2010/01/14 16:58:27 christos Exp $); #endif #include stdio.h @@ -131,7 +131,7 @@ Hflag = 1; break; case 'h': - hflag = 1; + hflag++; break; case 'F': Fflag = 1;
CVS commit: src/usr.bin/xlint/lint2
Module Name:src Committed By: lukem Date: Tue Apr 14 08:59:45 UTC 2009 Modified Files: src/usr.bin/xlint/lint2: hash.c Log Message: Fix -Wcast-qual issue To generate a diff of this commit: cvs rdiff -u -r1.9 -r1.10 src/usr.bin/xlint/lint2/hash.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/xlint/lint2/hash.c diff -u src/usr.bin/xlint/lint2/hash.c:1.9 src/usr.bin/xlint/lint2/hash.c:1.10 --- src/usr.bin/xlint/lint2/hash.c:1.9 Sun Jun 20 22:20:17 2004 +++ src/usr.bin/xlint/lint2/hash.c Tue Apr 14 08:59:45 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: hash.c,v 1.9 2004/06/20 22:20:17 jmc Exp $ */ +/* $NetBSD: hash.c,v 1.10 2009/04/14 08:59:45 lukem Exp $ */ /* * Copyright (c) 1994, 1995 Jochen Pohl @@ -37,7 +37,7 @@ #include sys/cdefs.h #if defined(__RCSID) !defined(lint) -__RCSID($NetBSD: hash.c,v 1.9 2004/06/20 22:20:17 jmc Exp $); +__RCSID($NetBSD: hash.c,v 1.10 2009/04/14 08:59:45 lukem Exp $); #endif /* @@ -159,7 +159,7 @@ for (i = 0; i HSHSIZ2; i++) { for (hte = table[i]; hte != NULL; hte = nexthte) { - free((void *)hte-h_name); + free((void *)__UNCONST(hte-h_name)); nexthte = hte-h_link; free(hte); }
CVS commit: src/usr.bin/xlint/lint2
Module Name:src Committed By: lukem Date: Tue Apr 14 09:03:45 UTC 2009 Modified Files: src/usr.bin/xlint/lint2: chk.c Log Message: Fix -Wshadow issues To generate a diff of this commit: cvs rdiff -u -r1.19 -r1.20 src/usr.bin/xlint/lint2/chk.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/xlint/lint2/chk.c diff -u src/usr.bin/xlint/lint2/chk.c:1.19 src/usr.bin/xlint/lint2/chk.c:1.20 --- src/usr.bin/xlint/lint2/chk.c:1.19 Sat Apr 26 19:38:30 2008 +++ src/usr.bin/xlint/lint2/chk.c Tue Apr 14 09:03:45 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: chk.c,v 1.19 2008/04/26 19:38:30 christos Exp $ */ +/* $NetBSD: chk.c,v 1.20 2009/04/14 09:03:45 lukem Exp $ */ /* * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. @@ -38,7 +38,7 @@ #include sys/cdefs.h #if defined(__RCSID) !defined(lint) -__RCSID($NetBSD: chk.c,v 1.19 2008/04/26 19:38:30 christos Exp $); +__RCSID($NetBSD: chk.c,v 1.20 2009/04/14 09:03:45 lukem Exp $); #endif #include ctype.h @@ -236,8 +236,7 @@ fcall_t *call; char *pos1; type_t *tp1, *tp2; - /* LINTED (automatic hides external declaration: warn) */ - int warn, eq; + int dowarn, eq; tspec_t t1; if (hte-h_calls == NULL) @@ -251,7 +250,7 @@ t1 = (tp1 = TP(def-s_type)-t_subt)-t_tspec; for (call = hte-h_calls; call != NULL; call = call-f_nxt) { tp2 = TP(call-f_type)-t_subt; - eq = eqtype(tp1, tp2, 1, 0, 0, (warn = 0, warn)); + eq = eqtype(tp1, tp2, 1, 0, 0, (dowarn = 0, dowarn)); if (!call-f_rused) { /* no return value used */ if ((t1 == STRUCT || t1 == UNION) !eq) { @@ -277,7 +276,7 @@ } continue; } - if (!eq || (sflag warn)) { + if (!eq || (sflag dowarn)) { pos1 = xstrdup(mkpos(def-s_pos)); /* %s value used inconsistenty\t%s :: %s */ msg(4, hte-h_name, pos1, mkpos(call-f_pos)); @@ -296,8 +295,7 @@ { sym_t *sym; type_t *tp1, *tp2; - /* LINTED (automatic hides external declaration: warn) */ - int eq, warn; + int eq, dowarn; char *pos1; if (def == NULL) @@ -311,14 +309,14 @@ if (sym == def) continue; tp2 = TP(sym-s_type); - warn = 0; + dowarn = 0; if (tp1-t_tspec == FUNC tp2-t_tspec == FUNC) { eq = eqtype(xt1 = tp1-t_subt, xt2 = tp2-t_subt, - 1, 0, 0, warn); + 1, 0, 0, dowarn); } else { - eq = eqtype(xt1 = tp1, xt2 = tp2, 0, 0, 0, warn); + eq = eqtype(xt1 = tp1, xt2 = tp2, 0, 0, 0, dowarn); } - if (!eq || (sflag warn)) { + if (!eq || (sflag dowarn)) { char b1[64], b2[64]; pos1 = xstrdup(mkpos(def-s_pos)); /* %s value declared inconsistently\t%s :: %s */ @@ -447,8 +445,7 @@ chkau(hte_t *hte, int n, sym_t *def, sym_t *decl, pos_t *pos1p, fcall_t *call1, fcall_t *call, type_t *arg1, type_t *arg2) { - /* LINTED (automatic hides external declaration: warn) */ - int promote, asgn, warn; + int promote, asgn, dowarn; tspec_t t1, t2; arginf_t *ai, *ai1; char *pos1; @@ -473,8 +470,8 @@ */ asgn = def != NULL || (decl != NULL TP(decl-s_type)-t_proto); - warn = 0; - if (eqtype(arg1, arg2, 1, promote, asgn, warn) (!sflag || !warn)) + dowarn = 0; + if (eqtype(arg1, arg2, 1, promote, asgn, dowarn) (!sflag || !dowarn)) return; /* @@ -1104,8 +1101,7 @@ static void chkadecl(hte_t *hte, sym_t *def, sym_t *decl) { - /* LINTED (automatic hides external declaration: warn) */ - int osdef, eq, warn, n; + int osdef, eq, dowarn, n; sym_t *sym1, *sym; type_t **ap1, **ap2, *tp1, *tp2; char *pos1; @@ -1136,9 +1132,9 @@ n = 0; while (*ap1 != NULL *ap2 != NULL) { type_t *xt1, *xt2; - warn = 0; - eq = eqtype(xt1 = *ap1, xt2 = *ap2, 1, osdef, 0, warn); - if (!eq || warn) { + dowarn = 0; + eq = eqtype(xt1 = *ap1, xt2 = *ap2, 1, osdef, 0, dowarn); + if (!eq || dowarn) { char b1[64], b2[64]; pos1 = xstrdup(mkpos(sym1-s_pos)); pos2 = mkpos(sym-s_pos); @@ -1182,11 +1178,11 @@ * asgn left indirected type must have at least the same qualifiers * like right indirected type (for assignments and function * arguments) - * *warn set to 1 if an old style declaration was compared with + * *dowarn set to 1 if an old style declaration was compared with * an incompatible prototype declaration */ static int -eqtype(type_t *tp1, type_t *tp2, int ignqual, int promot, int asgn, int *warn) +eqtype(type_t *tp1, type_t *tp2, int ignqual, int promot, int asgn, int *dowarn) { tspec_t t, to; int indir; @@ -1286,13 +1282,13 @@ if (t == FUNC) { if (tp1-t_proto tp2-t_proto) { -if (!eqargs(tp1, tp2, warn)) +if (!eqargs(tp1, tp2, dowarn)) return (0); } else if (tp1-t_proto) { -if (!mnoarg(tp1, warn)) +if (!mnoarg(tp1, dowarn)) return (0); } else if (tp2-t_proto) { -if (!mnoarg(tp2, warn)) +if (!mnoarg(tp2, dowarn)) return (0); } } @@ -1312,7 +1308,7 @@ * Compares arguments of two prototypes */ static int -eqargs(type_t *tp1,
CVS commit: src/usr.bin/xlint/lint2
Module Name:src Committed By: lukem Date: Tue Apr 14 09:06:25 UTC 2009 Modified Files: src/usr.bin/xlint/lint2: read.c Log Message: Fix -Wshadow and -Wcast-qual issues To generate a diff of this commit: cvs rdiff -u -r1.23 -r1.24 src/usr.bin/xlint/lint2/read.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/xlint/lint2/read.c diff -u src/usr.bin/xlint/lint2/read.c:1.23 src/usr.bin/xlint/lint2/read.c:1.24 --- src/usr.bin/xlint/lint2/read.c:1.23 Fri Sep 26 22:52:24 2008 +++ src/usr.bin/xlint/lint2/read.c Tue Apr 14 09:06:25 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: read.c,v 1.23 2008/09/26 22:52:24 matt Exp $ */ +/* $NetBSD: read.c,v 1.24 2009/04/14 09:06:25 lukem Exp $ */ /* * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. @@ -38,7 +38,7 @@ #include sys/cdefs.h #if defined(__RCSID) !defined(lint) -__RCSID($NetBSD: read.c,v 1.23 2008/09/26 22:52:24 matt Exp $); +__RCSID($NetBSD: read.c,v 1.24 2009/04/14 09:06:25 lukem Exp $); #endif #include ctype.h @@ -360,10 +360,10 @@ decldef(pos_t *posp, const char *cp) { sym_t *symp, sym; - char c, *ep, *pos1; + char c, *ep, *pos1, *tname; int used, renamed; hte_t *hte, *renamehte = NULL; - const char *name, *rename; + const char *name, *newname; (void)memset(sym, 0, sizeof (sym)); STRUCT_ASSIGN(sym.s_pos, *posp); @@ -444,22 +444,22 @@ renamed = 0; if (*cp == 'r') { cp++; - name = xstrdup(name); - rename = inpname(cp, cp); + tname = xstrdup(name); + newname = inpname(cp, cp); /* enter it and see if it's already been renamed */ - renamehte = _hsearch(renametab, name, 1); + renamehte = _hsearch(renametab, tname, 1); if (renamehte-h_hte == NULL) { - hte = hsearch(rename, 1); + hte = hsearch(newname, 1); renamehte-h_hte = hte; renamed = 1; - } else if (strcmp((hte = renamehte-h_hte)-h_name, rename)) { + } else if (strcmp((hte = renamehte-h_hte)-h_name, newname)) { pos1 = xstrdup(mkpos(renamehte-h_syms-s_pos)); /* %s renamed multiple times\t%s :: %s */ - msg(18, name, pos1, mkpos(sym.s_pos)); + msg(18, tname, pos1, mkpos(sym.s_pos)); free(pos1); } - free((char *)name); + free(tname); } else { /* it might be a previously-done rename */ hte = _hsearch(renametab, name, 0);