CVS commit: src/usr.bin/xlint/lint2
Module Name:src Committed By: rillig Date: Mon Jul 10 14:13:19 UTC 2023 Modified Files: src/usr.bin/xlint/lint2: chk.c msg.c read.c Log Message: lint: push memory management one layer down Just as with type_name in lint1, it is more convenient if the application code does not have to deal with memory management. To generate a diff of this commit: cvs rdiff -u -r1.58 -r1.59 src/usr.bin/xlint/lint2/chk.c cvs rdiff -u -r1.22 -r1.23 src/usr.bin/xlint/lint2/msg.c cvs rdiff -u -r1.85 -r1.86 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.
CVS commit: src/usr.bin/xlint/lint2
Module Name:src Committed By: rillig Date: Mon Jul 10 14:13:19 UTC 2023 Modified Files: src/usr.bin/xlint/lint2: chk.c msg.c read.c Log Message: lint: push memory management one layer down Just as with type_name in lint1, it is more convenient if the application code does not have to deal with memory management. To generate a diff of this commit: cvs rdiff -u -r1.58 -r1.59 src/usr.bin/xlint/lint2/chk.c cvs rdiff -u -r1.22 -r1.23 src/usr.bin/xlint/lint2/msg.c cvs rdiff -u -r1.85 -r1.86 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.58 src/usr.bin/xlint/lint2/chk.c:1.59 --- src/usr.bin/xlint/lint2/chk.c:1.58 Mon Jul 10 12:40:22 2023 +++ src/usr.bin/xlint/lint2/chk.c Mon Jul 10 14:13:19 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: chk.c,v 1.58 2023/07/10 12:40:22 rillig Exp $ */ +/* $NetBSD: chk.c,v 1.59 2023/07/10 14:13:19 rillig Exp $ */ /* * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. @@ -38,7 +38,7 @@ #include #if defined(__RCSID) -__RCSID("$NetBSD: chk.c,v 1.58 2023/07/10 12:40:22 rillig Exp $"); +__RCSID("$NetBSD: chk.c,v 1.59 2023/07/10 14:13:19 rillig Exp $"); #endif #include @@ -198,7 +198,6 @@ static void check_multiple_definitions(const hte_t *hte) { sym_t *sym, *def1; - char *pos1; if (!hte->h_def) return; @@ -217,10 +216,8 @@ check_multiple_definitions(const hte_t * def1 = sym; continue; } - pos1 = xstrdup(mkpos(>s_pos)); /* %s multiply defined \t%s :: %s */ - msg(3, hte->h_name, pos1, mkpos(>s_pos)); - free(pos1); + msg(3, hte->h_name, mkpos(>s_pos), mkpos(>s_pos)); } } @@ -237,7 +234,6 @@ static void chkvtui(const hte_t *hte, sym_t *def, sym_t *decl) { fcall_t *call; - char *pos1; type_t *tp1, *tp2; bool dowarn, eq; tspec_t t1; @@ -273,19 +269,16 @@ chkvtui(const hte_t *hte, sym_t *def, sy * behavior matches pcc-based lint, so it is * accepted for now. */ -pos1 = xstrdup(mkpos(>s_pos)); /* %s function value must be declared ... */ msg(17, hte->h_name, -pos1, mkpos(>f_pos)); -free(pos1); +mkpos(>s_pos), mkpos(>f_pos)); } continue; } if (!eq || (sflag && dowarn)) { - pos1 = xstrdup(mkpos(>s_pos)); /* %s value used inconsistently \t%s :: %s */ - msg(4, hte->h_name, pos1, mkpos(>f_pos)); - free(pos1); + msg(4, hte->h_name, + mkpos(>s_pos), mkpos(>f_pos)); } } } @@ -301,7 +294,6 @@ chkvtdi(const hte_t *hte, sym_t *def, sy sym_t *sym; type_t *tp1, *tp2; bool eq, dowarn; - char *pos1; if (def == NULL) def = decl; @@ -323,11 +315,9 @@ chkvtdi(const hte_t *hte, sym_t *def, sy false, false, false, ); } if (!eq || (sflag && dowarn)) { - pos1 = xstrdup(mkpos(>s_pos)); /* %s value declared inconsistently (%s != %s) \t... */ msg(5, hte->h_name, type_name(xt1), type_name(xt2), - pos1, mkpos(>s_pos)); - free(pos1); + mkpos(>s_pos), mkpos(>s_pos)); } } } @@ -344,7 +334,6 @@ chkfaui(const hte_t *hte, sym_t *def, sy pos_t *pos1p = NULL; fcall_t *calls, *call, *call1; int n, as; - char *pos1; arginf_t *ai; if ((calls = hte->h_calls) == NULL) @@ -408,10 +397,8 @@ chkfaui(const hte_t *hte, sym_t *def, sy * in the prototype. */ } else { - pos1 = xstrdup(mkpos(pos1p)); /* %s: variable # of args \t%s :: %s */ - msg(7, hte->h_name, pos1, mkpos(>f_pos)); - free(pos1); + msg(7, hte->h_name, mkpos(pos1p), mkpos(>f_pos)); continue; } @@ -456,7 +443,6 @@ chkau(const hte_t *hte, int n, sym_t *de bool promote, asgn, dowarn; tspec_t t1, t2; arginf_t *ai, *ai1; - char *pos1; /* * If a function definition is available (def != NULL), we compare the @@ -593,11 +579,9 @@ chkau(const hte_t *hte, int n, sym_t *de return; } - pos1 = xstrdup(mkpos(pos1p)); /* %s, arg %d used inconsistently \t%s[%s] :: %s[%s] */ - msg(6, hte->h_name, n, pos1, type_name(arg1), + msg(6, hte->h_name, n, mkpos(pos1p), type_name(arg1), mkpos(>f_pos), type_name(arg2)); - free(pos1); } /* @@ -1131,8 +1115,6 @@ check_argument_declarations(const hte_t int n; sym_t *sym1, *sym; type_t **ap1, **ap2, *tp1, *tp2; - char *pos1; - const char *pos2; osdef = false; if (def != NULL) { @@ -1163,12 +1145,10 @@ check_argument_declarations(const hte_t eq = types_compatible(xt1 = *ap1, xt2 = *ap2, true, osdef, false, ); if (!eq || dowarn) { -pos1 = xstrdup(mkpos(>s_pos)); -pos2 = mkpos(>s_pos); /* %s, arg %d declared inconsistently ... */ msg(11, hte->h_name, n + 1, -type_name(xt1), type_name(xt2), pos1, pos2); -free(pos1); +type_name(xt1), type_name(xt2), +mkpos(>s_pos), mkpos(>s_pos)); } n++; ap1++; @@ -1184,10 +1164,8 @@ check_argument_declarations(const hte_t
CVS commit: src/usr.bin/xlint/lint2
Module Name:src Committed By: rillig Date: Mon Jul 10 12:40:22 UTC 2023 Modified Files: src/usr.bin/xlint/lint2: chk.c externs2.h hash.c lint2.h main2.c msg.c read.c Log Message: lint: clean up lint2 To generate a diff of this commit: cvs rdiff -u -r1.57 -r1.58 src/usr.bin/xlint/lint2/chk.c cvs rdiff -u -r1.19 -r1.20 src/usr.bin/xlint/lint2/externs2.h cvs rdiff -u -r1.26 -r1.27 src/usr.bin/xlint/lint2/hash.c cvs rdiff -u -r1.22 -r1.23 src/usr.bin/xlint/lint2/lint2.h cvs rdiff -u -r1.31 -r1.32 src/usr.bin/xlint/lint2/main2.c cvs rdiff -u -r1.20 -r1.21 src/usr.bin/xlint/lint2/msg.c cvs rdiff -u -r1.84 -r1.85 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.57 src/usr.bin/xlint/lint2/chk.c:1.58 --- src/usr.bin/xlint/lint2/chk.c:1.57 Mon Jul 3 10:23:12 2023 +++ src/usr.bin/xlint/lint2/chk.c Mon Jul 10 12:40:22 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: chk.c,v 1.57 2023/07/03 10:23:12 rillig Exp $ */ +/* $NetBSD: chk.c,v 1.58 2023/07/10 12:40:22 rillig Exp $ */ /* * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. @@ -38,7 +38,7 @@ #include #if defined(__RCSID) -__RCSID("$NetBSD: chk.c,v 1.57 2023/07/03 10:23:12 rillig Exp $"); +__RCSID("$NetBSD: chk.c,v 1.58 2023/07/10 12:40:22 rillig Exp $"); #endif #include @@ -78,7 +78,7 @@ mark_main_as_used(void) { hte_t *hte; - if ((hte = hsearch("main", false)) != NULL) + if ((hte = htab_search("main", false)) != NULL) hte->h_used = true; } Index: src/usr.bin/xlint/lint2/externs2.h diff -u src/usr.bin/xlint/lint2/externs2.h:1.19 src/usr.bin/xlint/lint2/externs2.h:1.20 --- src/usr.bin/xlint/lint2/externs2.h:1.19 Sat Jan 14 08:48:18 2023 +++ src/usr.bin/xlint/lint2/externs2.h Mon Jul 10 12:40:22 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: externs2.h,v 1.19 2023/01/14 08:48:18 rillig Exp $ */ +/* $NetBSD: externs2.h,v 1.20 2023/07/10 12:40:22 rillig Exp $ */ /* * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. @@ -35,27 +35,27 @@ /* * main2.c */ -extern bool xflag; -extern bool uflag; extern bool Cflag; -extern const char *libname; -extern bool sflag; -extern bool tflag; +extern bool Fflag; extern bool Hflag; extern bool hflag; -extern bool Fflag; +extern bool sflag; +extern bool tflag; +extern bool uflag; +extern bool xflag; +extern const char *libname; /* * hash.c */ -extern hte_t** htab_new(void); -extern hte_t *_hsearch(hte_t **, const char *, bool); -extern void symtab_init(void); -extern void symtab_forall(void (*)(hte_t *)); -extern void symtab_forall_sorted(void (*)(hte_t *)); -extern void _destroyhash(hte_t **); +hte_t** htab_new(void); +hte_t *hash_search(hte_t **, const char *, bool); +void symtab_init(void); +void symtab_forall(void (*)(hte_t *)); +void symtab_forall_sorted(void (*)(hte_t *)); +void hash_free(hte_t **); -#define hsearch(a, b) _hsearch(NULL, (a), (b)) +#define htab_search(a, b) hash_search(NULL, (a), (b)) /* * read.c @@ -63,23 +63,23 @@ extern void _destroyhash(hte_t **); extern const char **fnames; extern type_t **tlst; -extern void readfile(const char *); -extern void mkstatic(hte_t *); +void readfile(const char *); +void mkstatic(hte_t *); /* * chk.c */ -extern void mark_main_as_used(void); -extern void check_name(const hte_t *); +void mark_main_as_used(void); +void check_name(const hte_t *); /* * msg.c */ -extern void msg(int, ...); -extern const char *mkpos(pos_t *); +void msg(int, ...); +const char *mkpos(const pos_t *); /* * emit2.c */ -extern void outlib(const char *); -extern int addoutfile(short); +void outlib(const char *); +int addoutfile(short); Index: src/usr.bin/xlint/lint2/hash.c diff -u src/usr.bin/xlint/lint2/hash.c:1.26 src/usr.bin/xlint/lint2/hash.c:1.27 --- src/usr.bin/xlint/lint2/hash.c:1.26 Mon Jul 10 09:51:30 2023 +++ src/usr.bin/xlint/lint2/hash.c Mon Jul 10 12:40:22 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: hash.c,v 1.26 2023/07/10 09:51:30 rillig Exp $ */ +/* $NetBSD: hash.c,v 1.27 2023/07/10 12:40:22 rillig Exp $ */ /* * Copyright (c) 1994, 1995 Jochen Pohl @@ -37,7 +37,7 @@ #include #if defined(__RCSID) -__RCSID("$NetBSD: hash.c,v 1.26 2023/07/10 09:51:30 rillig Exp $"); +__RCSID("$NetBSD: hash.c,v 1.27 2023/07/10 12:40:22 rillig Exp $"); #endif #include @@ -76,7 +76,7 @@ hash(const char *s) * given name exists and mknew is set, create a new one. */ hte_t * -_hsearch(hte_t **table, const char *s, bool mknew) +hash_search(hte_t **table, const char *s, bool mknew) { unsigned int h; hte_t *hte; @@ -185,14 +185,11 @@ symtab_forall_sorted(void (*action)(hte_ * Free all contents of the hash table that this module allocated. */ void -_destroyhash(hte_t **table) +hash_free(hte_t **table) { int i; hte_t *hte, *nexthte; - if (table == NULL) - err(1, "_destroyhash called on
CVS commit: src/usr.bin/xlint/lint2
Module Name:src Committed By: rillig Date: Mon Jul 10 12:40:22 UTC 2023 Modified Files: src/usr.bin/xlint/lint2: chk.c externs2.h hash.c lint2.h main2.c msg.c read.c Log Message: lint: clean up lint2 To generate a diff of this commit: cvs rdiff -u -r1.57 -r1.58 src/usr.bin/xlint/lint2/chk.c cvs rdiff -u -r1.19 -r1.20 src/usr.bin/xlint/lint2/externs2.h cvs rdiff -u -r1.26 -r1.27 src/usr.bin/xlint/lint2/hash.c cvs rdiff -u -r1.22 -r1.23 src/usr.bin/xlint/lint2/lint2.h cvs rdiff -u -r1.31 -r1.32 src/usr.bin/xlint/lint2/main2.c cvs rdiff -u -r1.20 -r1.21 src/usr.bin/xlint/lint2/msg.c cvs rdiff -u -r1.84 -r1.85 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.
CVS commit: src/usr.bin/xlint/lint2
Module Name:src Committed By: rillig Date: Tue Feb 21 19:32:55 UTC 2023 Modified Files: src/usr.bin/xlint/lint2: main2.c Log Message: lint: return instead of calling exit from main No functional change. To generate a diff of this commit: cvs rdiff -u -r1.26 -r1.27 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.26 src/usr.bin/xlint/lint2/main2.c:1.27 --- src/usr.bin/xlint/lint2/main2.c:1.26 Sat Jan 14 08:48:18 2023 +++ src/usr.bin/xlint/lint2/main2.c Tue Feb 21 19:32:55 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: main2.c,v 1.26 2023/01/14 08:48:18 rillig Exp $ */ +/* $NetBSD: main2.c,v 1.27 2023/02/21 19:32:55 rillig Exp $ */ /* * Copyright (c) 1994, 1995 Jochen Pohl @@ -37,7 +37,7 @@ #include #if defined(__RCSID) -__RCSID("$NetBSD: main2.c,v 1.26 2023/01/14 08:48:18 rillig Exp $"); +__RCSID("$NetBSD: main2.c,v 1.27 2023/02/21 19:32:55 rillig Exp $"); #endif #include @@ -175,8 +175,7 @@ main(int argc, char *argv[]) /* perform all tests */ symtab_forall_sorted(check_name_non_const); - exit(0); - /* NOTREACHED */ + return 0; } static void
CVS commit: src/usr.bin/xlint/lint2
Module Name:src Committed By: rillig Date: Tue Feb 21 19:32:55 UTC 2023 Modified Files: src/usr.bin/xlint/lint2: main2.c Log Message: lint: return instead of calling exit from main No functional change. To generate a diff of this commit: cvs rdiff -u -r1.26 -r1.27 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.
CVS commit: src/usr.bin/xlint/lint2
Module Name:src Committed By: rillig Date: Fri Jan 13 19:50:00 UTC 2023 Modified Files: src/usr.bin/xlint/lint2: Makefile externs2.h read.c Removed Files: src/usr.bin/xlint/lint2: mem2.c Log Message: lint: move xalloc to the only file where it is used No functional change. To generate a diff of this commit: cvs rdiff -u -r1.22 -r1.23 src/usr.bin/xlint/lint2/Makefile cvs rdiff -u -r1.17 -r1.18 src/usr.bin/xlint/lint2/externs2.h cvs rdiff -u -r1.16 -r0 src/usr.bin/xlint/lint2/mem2.c cvs rdiff -u -r1.76 -r1.77 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.22 src/usr.bin/xlint/lint2/Makefile:1.23 --- src/usr.bin/xlint/lint2/Makefile:1.22 Sun Aug 22 15:06:49 2021 +++ src/usr.bin/xlint/lint2/Makefile Fri Jan 13 19:50:00 2023 @@ -1,9 +1,9 @@ -# $NetBSD: Makefile,v 1.22 2021/08/22 15:06:49 rillig Exp $ +# $NetBSD: Makefile,v 1.23 2023/01/13 19:50:00 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 \ +SRCS= main2.c hash.c read.c mem.c chk.c msg.c emit.c emit2.c \ inittyp.c tyname.c BINDIR= /usr/libexec CPPFLAGS+= -I${.CURDIR} Index: src/usr.bin/xlint/lint2/externs2.h diff -u src/usr.bin/xlint/lint2/externs2.h:1.17 src/usr.bin/xlint/lint2/externs2.h:1.18 --- src/usr.bin/xlint/lint2/externs2.h:1.17 Fri Jan 13 19:41:50 2023 +++ src/usr.bin/xlint/lint2/externs2.h Fri Jan 13 19:50:00 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: externs2.h,v 1.17 2023/01/13 19:41:50 rillig Exp $ */ +/* $NetBSD: externs2.h,v 1.18 2023/01/13 19:50:00 rillig Exp $ */ /* * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. @@ -67,11 +67,6 @@ extern void readfile(const char *); extern void mkstatic(hte_t *); /* - * mem2.c - */ -extern void *xalloc(size_t); - -/* * chk.c */ extern void mainused(void); Index: src/usr.bin/xlint/lint2/read.c diff -u src/usr.bin/xlint/lint2/read.c:1.76 src/usr.bin/xlint/lint2/read.c:1.77 --- src/usr.bin/xlint/lint2/read.c:1.76 Fri May 20 21:18:55 2022 +++ src/usr.bin/xlint/lint2/read.c Fri Jan 13 19:50:00 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: read.c,v 1.76 2022/05/20 21:18:55 rillig Exp $ */ +/* $NetBSD: read.c,v 1.77 2023/01/13 19:50:00 rillig Exp $ */ /* * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. @@ -38,7 +38,7 @@ #include #if defined(__RCSID) -__RCSID("$NetBSD: read.c,v 1.76 2022/05/20 21:18:55 rillig Exp $"); +__RCSID("$NetBSD: read.c,v 1.77 2023/01/13 19:50:00 rillig Exp $"); #endif #include @@ -108,6 +108,16 @@ static char *inpqstrg(const char *, cons static const char *inpname(const char *, const char **); static int getfnidx(const char *); +/* Allocate zero-initialized memory that doesn't need to be freed. */ +static void * +xalloc(size_t sz) +{ + + void *ptr = xmalloc(sz); + (void)memset(ptr, 0, sz); + return ptr; +} + static bool try_parse_int(const char **p, int *num) {
CVS commit: src/usr.bin/xlint/lint2
Module Name:src Committed By: rillig Date: Fri Jan 13 19:50:00 UTC 2023 Modified Files: src/usr.bin/xlint/lint2: Makefile externs2.h read.c Removed Files: src/usr.bin/xlint/lint2: mem2.c Log Message: lint: move xalloc to the only file where it is used No functional change. To generate a diff of this commit: cvs rdiff -u -r1.22 -r1.23 src/usr.bin/xlint/lint2/Makefile cvs rdiff -u -r1.17 -r1.18 src/usr.bin/xlint/lint2/externs2.h cvs rdiff -u -r1.16 -r0 src/usr.bin/xlint/lint2/mem2.c cvs rdiff -u -r1.76 -r1.77 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.
CVS commit: src/usr.bin/xlint/lint2
Module Name:src Committed By: rillig Date: Thu Apr 21 21:09:13 UTC 2022 Modified Files: src/usr.bin/xlint/lint2: chk.c Log Message: lint: expand the last remaining __arraycount For consistency with the other expressions for an array length, which already use the expanded form. No functional change. To generate a diff of this commit: cvs rdiff -u -r1.46 -r1.47 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.46 src/usr.bin/xlint/lint2/chk.c:1.47 --- src/usr.bin/xlint/lint2/chk.c:1.46 Tue Nov 16 22:12:44 2021 +++ src/usr.bin/xlint/lint2/chk.c Thu Apr 21 21:09:13 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: chk.c,v 1.46 2021/11/16 22:12:44 rillig Exp $ */ +/* $NetBSD: chk.c,v 1.47 2022/04/21 21:09:13 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.46 2021/11/16 22:12:44 rillig Exp $"); +__RCSID("$NetBSD: chk.c,v 1.47 2022/04/21 21:09:13 rillig Exp $"); #endif #include @@ -1084,15 +1084,16 @@ chkrvu(const hte_t *hte, sym_t *def) if (def->s_function_has_return_value) { /* - * XXX as soon as we are able to disable single warnings + * XXX as soon as we are able to disable single warnings, * the following dependencies from hflag should be removed. - * but for now I don't want to be bothered by this warnings + * But for now I don't want to be bothered by these warnings * which are almost always useless. */ if (!hflag) return; if (hflag && bsearch(hte->h_name, ignorelist, - __arraycount(ignorelist), sizeof(ignorelist[0]), + sizeof(ignorelist) / sizeof(ignorelist[0]), + sizeof(ignorelist[0]), (int (*)(const void *, const void *))strcmp) != NULL) return;
CVS commit: src/usr.bin/xlint/lint2
Module Name:src Committed By: rillig Date: Thu Apr 21 21:09:13 UTC 2022 Modified Files: src/usr.bin/xlint/lint2: chk.c Log Message: lint: expand the last remaining __arraycount For consistency with the other expressions for an array length, which already use the expanded form. No functional change. To generate a diff of this commit: cvs rdiff -u -r1.46 -r1.47 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.
CVS commit: src/usr.bin/xlint/lint2
Module Name:src Committed By: rillig Date: Sun Dec 19 10:42:36 UTC 2021 Modified Files: src/usr.bin/xlint/lint2: read.c Log Message: lint: remove redundant braces No binary change. To generate a diff of this commit: cvs rdiff -u -r1.74 -r1.75 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.74 src/usr.bin/xlint/lint2/read.c:1.75 --- src/usr.bin/xlint/lint2/read.c:1.74 Sun Dec 19 10:29:06 2021 +++ src/usr.bin/xlint/lint2/read.c Sun Dec 19 10:42:36 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: read.c,v 1.74 2021/12/19 10:29:06 rillig Exp $ */ +/* $NetBSD: read.c,v 1.75 2021/12/19 10:42:36 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.74 2021/12/19 10:29:06 rillig Exp $"); +__RCSID("$NetBSD: read.c,v 1.75 2021/12/19 10:42:36 rillig Exp $"); #endif #include @@ -342,13 +342,13 @@ again: case 's': ai = xalloc(sizeof(*ai)); ai->a_num = parse_int(); - if (c == 'z') { + if (c == 'z') ai->a_pcon = ai->a_zero = true; - } else if (c == 'p') { + else if (c == 'p') ai->a_pcon = true; - } else if (c == 'n') { + else if (c == 'n') ai->a_ncon = true; - } else { + else { ai->a_fmt = true; ai->a_fstrg = inpqstrg(cp, ); } @@ -522,9 +522,8 @@ decldef(pos_t pos, const char *cp) symp->s_type == sym.s_type && ((symp->s_def == DECL && sym.s_def == DECL) || (!sflag && symp->s_def == TDEF && sym.s_def == TDEF)) && - !symp->s_static && !sym.s_static) { + !symp->s_static && !sym.s_static) break; - } } if (symp == NULL) { @@ -697,9 +696,8 @@ inptype(const char *cp, const char **epp if (i == narg - 1 && *cp == 'E') { tp->t_vararg = true; cp++; -} else { +} else tp->t_args[i] = TP(inptype(cp, )); -} } } tp->t_subt = TP(inptype(cp, )); @@ -780,59 +778,52 @@ gettlen(const char *cp, const char **epp t = BOOL; break; case 'C': - if (s == 's') { + if (s == 's') t = SCHAR; - } else if (s == 'u') { + else if (s == 'u') t = UCHAR; - } else if (s == '\0') { + else if (s == '\0') t = CHAR; - } break; case 'S': - if (s == 'u') { + if (s == 'u') t = USHORT; - } else if (s == '\0') { + else if (s == '\0') t = SHORT; - } break; case 'I': - if (s == 'u') { + if (s == 'u') t = UINT; - } else if (s == '\0') { + else if (s == '\0') t = INT; - } break; case 'L': - if (s == 'u') { + if (s == 'u') t = ULONG; - } else if (s == '\0') { + else if (s == '\0') t = LONG; - } break; case 'Q': - if (s == 'u') { + if (s == 'u') t = UQUAD; - } else if (s == '\0') { + else if (s == '\0') t = QUAD; - } break; #ifdef INT128_SIZE case 'J': - if (s == 'u') { + if (s == 'u') t = UINT128; - } else if (s == '\0') { + else if (s == '\0') t = INT128; - } break; #endif case 'D': - if (s == 's') { + if (s == 's') t = FLOAT; - } else if (s == 'l') { + else if (s == 'l') t = LDOUBLE; - } else if (s == '\0') { + else if (s == '\0') t = DOUBLE; - } break; case 'V': if (s == '\0') @@ -852,22 +843,20 @@ gettlen(const char *cp, const char **epp t = FUNC; break; case 'T': - if (s == 'e') { + if (s == 'e') t = ENUM; - } else if (s == 's') { + else if (s == 's') t = STRUCT; - } else if (s == 'u') { + else if (s == 'u') t = UNION; - } break; case 'X': - if (s == 's') { + if (s == 's') t = FCOMPLEX; - } else if (s == 'l') { + else if (s == 'l') t = LCOMPLEX; - } else if (s == '\0') { + else if (s == '\0') t = DCOMPLEX; - } break; default: break; @@ -889,11 +878,10 @@ gettlen(const char *cp, const char **epp if (ch_isdigit(c)) { narg = parse_int(); for (i = 0; i < narg; i++) { -if (i == narg - 1 && *cp == 'E') { +if (i == narg - 1 && *cp == 'E') cp++; -} else { +else (void)gettlen(cp, ); -} } } (void)gettlen(cp, );
CVS commit: src/usr.bin/xlint/lint2
Module Name:src Committed By: rillig Date: Sun Dec 19 10:42:36 UTC 2021 Modified Files: src/usr.bin/xlint/lint2: read.c Log Message: lint: remove redundant braces No binary change. To generate a diff of this commit: cvs rdiff -u -r1.74 -r1.75 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.
CVS commit: src/usr.bin/xlint/lint2
Module Name:src Committed By: rillig Date: Sun Dec 19 10:29:06 UTC 2021 Modified Files: src/usr.bin/xlint/lint2: read.c Log Message: lint: reduce pointer usage when reading .ln lines No binary change. To generate a diff of this commit: cvs rdiff -u -r1.73 -r1.74 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.73 src/usr.bin/xlint/lint2/read.c:1.74 --- src/usr.bin/xlint/lint2/read.c:1.73 Sun Dec 19 10:19:58 2021 +++ src/usr.bin/xlint/lint2/read.c Sun Dec 19 10:29:06 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: read.c,v 1.73 2021/12/19 10:19:58 rillig Exp $ */ +/* $NetBSD: read.c,v 1.74 2021/12/19 10:29:06 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.73 2021/12/19 10:19:58 rillig Exp $"); +__RCSID("$NetBSD: read.c,v 1.74 2021/12/19 10:29:06 rillig Exp $"); #endif #include @@ -96,9 +96,9 @@ static void inperr(const char *, ...) __attribute__((format(printf, 1, 2), noreturn)); static void setsrc(const char *); static void setfnid(int, const char *); -static void funccall(pos_t *, const char *); -static void decldef(pos_t *, const char *); -static void usedsym(pos_t *, const char *); +static void funccall(pos_t, const char *); +static void decldef(pos_t, const char *); +static void usedsym(pos_t, const char *); static unsigned short inptype(const char *, const char **); static size_t gettlen(const char *, const char **); static unsigned short findtype(const char *, size_t, int); @@ -188,13 +188,13 @@ read_ln_line(const char *line) /* process rest of this record */ switch (rt) { case 'c': - funccall(, cp); + funccall(pos, cp); break; case 'd': - decldef(, cp); + decldef(pos, cp); break; case 'u': - usedsym(, cp); + usedsym(pos, cp); break; default: inperr("bad record type %c", rt); @@ -303,7 +303,7 @@ setfnid(int fid, const char *cp) * Process a function call record (c-record). */ static void -funccall(pos_t *posp, const char *cp) +funccall(pos_t pos, const char *cp) { arginf_t *ai, **lai; char c; @@ -313,7 +313,7 @@ funccall(pos_t *posp, const char *cp) const char *name; fcall = xalloc(sizeof(*fcall)); - fcall->f_pos = *posp; + fcall->f_pos = pos; /* read flags */ rused = rdisc = false; @@ -456,7 +456,7 @@ parse_function_attribute(const char **pp * Process a declaration or definition (d-record). */ static void -decldef(pos_t *posp, const char *cp) +decldef(pos_t pos, const char *cp) { sym_t *symp, sym; char *pos1, *tname; @@ -465,7 +465,7 @@ decldef(pos_t *posp, const char *cp) const char *name, *newname; (void)memset(, 0, sizeof(sym)); - sym.s_pos = *posp; + sym.s_pos = pos; sym.s_def = NODECL; used = false; @@ -553,14 +553,14 @@ decldef(pos_t *posp, const char *cp) * Read an u-record (emitted by lint1 if a symbol was used). */ static void -usedsym(pos_t *posp, const char *cp) +usedsym(pos_t pos, const char *cp) { usym_t *usym; hte_t *hte; const char *name; usym = xalloc(sizeof(*usym)); - usym->u_pos = *posp; + usym->u_pos = pos; /* needed as delimiter between two numbers */ if (*cp++ != 'x')
CVS commit: src/usr.bin/xlint/lint2
Module Name:src Committed By: rillig Date: Sun Dec 19 10:29:06 UTC 2021 Modified Files: src/usr.bin/xlint/lint2: read.c Log Message: lint: reduce pointer usage when reading .ln lines No binary change. To generate a diff of this commit: cvs rdiff -u -r1.73 -r1.74 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.
CVS commit: src/usr.bin/xlint/lint2
Module Name:src Committed By: rillig Date: Sun Dec 19 10:19:59 UTC 2021 Modified Files: src/usr.bin/xlint/lint2: read.c Log Message: lint: remove unused parameter in read_ln_line To generate a diff of this commit: cvs rdiff -u -r1.72 -r1.73 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.
CVS commit: src/usr.bin/xlint/lint2
Module Name:src Committed By: rillig Date: Sun Dec 19 10:19:59 UTC 2021 Modified Files: src/usr.bin/xlint/lint2: read.c Log Message: lint: remove unused parameter in read_ln_line To generate a diff of this commit: cvs rdiff -u -r1.72 -r1.73 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.72 src/usr.bin/xlint/lint2/read.c:1.73 --- src/usr.bin/xlint/lint2/read.c:1.72 Thu Dec 16 03:53:13 2021 +++ src/usr.bin/xlint/lint2/read.c Sun Dec 19 10:19:58 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: read.c,v 1.72 2021/12/16 03:53:13 rillig Exp $ */ +/* $NetBSD: read.c,v 1.73 2021/12/19 10:19:58 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.72 2021/12/16 03:53:13 rillig Exp $"); +__RCSID("$NetBSD: read.c,v 1.73 2021/12/19 10:19:58 rillig Exp $"); #endif #include @@ -140,7 +140,7 @@ parse_short(const char **p) } static void -read_ln_line(const char *line, size_t len) +read_ln_line(const char *line) { const char *cp; int cline, isrc, iline; @@ -234,7 +234,7 @@ readfile(const char *name) inperr("missing newline after '%s'", [len - 1]); line[len - 1] = '\0'; - read_ln_line(line, len); + read_ln_line(line); readfile_line = NULL; }
CVS commit: src/usr.bin/xlint/lint2
Module Name:src Committed By: rillig Date: Sun Nov 28 08:21:50 UTC 2021 Modified Files: src/usr.bin/xlint/lint2: read.c Log Message: lint: move fgetln peculiarities out of read_ln_line This allows the function parameter to be a pointer to const. No functional change. To generate a diff of this commit: cvs rdiff -u -r1.69 -r1.70 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.69 src/usr.bin/xlint/lint2/read.c:1.70 --- src/usr.bin/xlint/lint2/read.c:1.69 Tue Nov 16 22:12:44 2021 +++ src/usr.bin/xlint/lint2/read.c Sun Nov 28 08:21:49 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: read.c,v 1.69 2021/11/16 22:12:44 rillig Exp $ */ +/* $NetBSD: read.c,v 1.70 2021/11/28 08:21:49 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.69 2021/11/16 22:12:44 rillig Exp $"); +__RCSID("$NetBSD: read.c,v 1.70 2021/11/28 08:21:49 rillig Exp $"); #endif #include @@ -139,7 +139,7 @@ parse_short(const char **p) } static void -read_ln_line(char *line, size_t len) +read_ln_line(const char *line, size_t len) { const char *cp; int cline, isrc, iline; @@ -148,9 +148,6 @@ read_ln_line(char *line, size_t len) flines[srcfile]++; - if (len == 0 || line[len - 1] != '\n') - inperr("%s", [len - 1]); - line[len - 1] = '\0'; cp = line; /* line number in csrcfile */ @@ -230,8 +227,13 @@ readfile(const char *name) if ((inp = fopen(name, "r")) == NULL) err(1, "cannot open %s", name); - while ((line = fgetln(inp, )) != NULL) + while ((line = fgetln(inp, )) != NULL) { + if (len == 0 || line[len - 1] != '\n') + inperr("%s", [len - 1]); + line[len - 1] = '\0'; + read_ln_line(line, len); + } _destroyhash(renametab);
CVS commit: src/usr.bin/xlint/lint2
Module Name:src Committed By: rillig Date: Sun Nov 28 08:21:50 UTC 2021 Modified Files: src/usr.bin/xlint/lint2: read.c Log Message: lint: move fgetln peculiarities out of read_ln_line This allows the function parameter to be a pointer to const. No functional change. To generate a diff of this commit: cvs rdiff -u -r1.69 -r1.70 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.
CVS commit: src/usr.bin/xlint/lint2
Module Name:src Committed By: rillig Date: Tue Nov 16 22:12:44 UTC 2021 Modified Files: src/usr.bin/xlint/lint2: chk.c emit2.c read.c Log Message: lint: clean up lint2 No functional change. To generate a diff of this commit: cvs rdiff -u -r1.45 -r1.46 src/usr.bin/xlint/lint2/chk.c cvs rdiff -u -r1.26 -r1.27 src/usr.bin/xlint/lint2/emit2.c cvs rdiff -u -r1.68 -r1.69 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.45 src/usr.bin/xlint/lint2/chk.c:1.46 --- src/usr.bin/xlint/lint2/chk.c:1.45 Sun Aug 29 10:13:02 2021 +++ src/usr.bin/xlint/lint2/chk.c Tue Nov 16 22:12:44 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: chk.c,v 1.45 2021/08/29 10:13:02 rillig Exp $ */ +/* $NetBSD: chk.c,v 1.46 2021/11/16 22:12:44 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.45 2021/08/29 10:13:02 rillig Exp $"); +__RCSID("$NetBSD: chk.c,v 1.46 2021/11/16 22:12:44 rillig Exp $"); #endif #include @@ -607,7 +607,7 @@ static void printflike(const hte_t *hte, fcall_t *call, int n, const char *fmt, type_t **ap) { const char *fp; - int fc; + char fc; bool fwidth, prec, left, sign, space, alt, zero; tspec_t sz, t1, t2 = NOTSPEC; type_t *tp; @@ -832,7 +832,7 @@ static void scanflike(const hte_t *hte, fcall_t *call, int n, const char *fmt, type_t **ap) { const char *fp; - int fc; + char fc; bool noasgn, fwidth; tspec_t sz, t1 = NOTSPEC, t2 = NOTSPEC; type_t *tp = NULL; Index: src/usr.bin/xlint/lint2/emit2.c diff -u src/usr.bin/xlint/lint2/emit2.c:1.26 src/usr.bin/xlint/lint2/emit2.c:1.27 --- src/usr.bin/xlint/lint2/emit2.c:1.26 Sat Sep 4 18:58:57 2021 +++ src/usr.bin/xlint/lint2/emit2.c Tue Nov 16 22:12:44 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: emit2.c,v 1.26 2021/09/04 18:58:57 rillig Exp $ */ +/* $NetBSD: emit2.c,v 1.27 2021/11/16 22:12:44 rillig Exp $ */ /* * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. @@ -34,7 +34,7 @@ #include #if defined(__RCSID) && !defined(lint) -__RCSID("$NetBSD: emit2.c,v 1.26 2021/09/04 18:58:57 rillig Exp $"); +__RCSID("$NetBSD: emit2.c,v 1.27 2021/11/16 22:12:44 rillig Exp $"); #endif #include "lint2.h" @@ -213,7 +213,7 @@ outlib(const char *name) outstrg(name); /* - * print the names of all files references by unnamed + * print the names of all files referenced by unnamed * struct/union/enum declarations. */ outfiles(); Index: src/usr.bin/xlint/lint2/read.c diff -u src/usr.bin/xlint/lint2/read.c:1.68 src/usr.bin/xlint/lint2/read.c:1.69 --- src/usr.bin/xlint/lint2/read.c:1.68 Tue Nov 16 22:03:12 2021 +++ src/usr.bin/xlint/lint2/read.c Tue Nov 16 22:12:44 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: read.c,v 1.68 2021/11/16 22:03:12 rillig Exp $ */ +/* $NetBSD: read.c,v 1.69 2021/11/16 22:12:44 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.68 2021/11/16 22:03:12 rillig Exp $"); +__RCSID("$NetBSD: read.c,v 1.69 2021/11/16 22:12:44 rillig Exp $"); #endif #include @@ -102,7 +102,7 @@ static unsigned short inptype(const char static size_t gettlen(const char *, const char **); static unsigned short findtype(const char *, size_t, int); static unsigned short storetyp(type_t *, const char *, size_t, int); -static int thash(const char *, size_t); +static unsigned int thash(const char *, size_t); static char *inpqstrg(const char *, const char **); static const char *inpname(const char *, const char **); static int getfnidx(const char *); @@ -980,7 +980,7 @@ storetyp(type_t *tp, const char *cp, siz /* * Hash function for types */ -static int +static unsigned int thash(const char *s, size_t len) { unsigned int v; @@ -1203,7 +1203,7 @@ mkstatic(hte_t *hte) for (symp = >h_syms; (sym = *symp) != NULL; ) { if (sym->s_pos.p_src == sym1->s_pos.p_src) { sym->s_static = true; - (*symp) = sym->s_next; + *symp = sym->s_next; if (hte->h_lsym == >s_next) hte->h_lsym = symp; sym->s_next = NULL; @@ -1215,7 +1215,7 @@ mkstatic(hte_t *hte) } for (callp = >h_calls; (call = *callp) != NULL; ) { if (call->f_pos.p_src == sym1->s_pos.p_src) { - (*callp) = call->f_next; + *callp = call->f_next; if (hte->h_lcall == >f_next) hte->h_lcall = callp; call->f_next = NULL; @@ -1227,7 +1227,7 @@ mkstatic(hte_t *hte) } for (usymp = >h_usyms; (usym = *usymp) != NULL; ) { if (usym->u_pos.p_src == sym1->s_pos.p_src) { - (*usymp) = usym->u_next; + *usymp = usym->u_next; if (hte->h_lusym == >u_next) hte->h_lusym = usymp; usym->u_next = NULL;
CVS commit: src/usr.bin/xlint/lint2
Module Name:src Committed By: rillig Date: Tue Nov 16 22:12:44 UTC 2021 Modified Files: src/usr.bin/xlint/lint2: chk.c emit2.c read.c Log Message: lint: clean up lint2 No functional change. To generate a diff of this commit: cvs rdiff -u -r1.45 -r1.46 src/usr.bin/xlint/lint2/chk.c cvs rdiff -u -r1.26 -r1.27 src/usr.bin/xlint/lint2/emit2.c cvs rdiff -u -r1.68 -r1.69 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.
CVS commit: src/usr.bin/xlint/lint2
Module Name:src Committed By: rillig Date: Tue Nov 16 22:03:12 UTC 2021 Modified Files: src/usr.bin/xlint/lint2: externs2.h hash.c main2.c read.c Log Message: lint: clean up initialization of lint2 symbol table No functional change. To generate a diff of this commit: cvs rdiff -u -r1.15 -r1.16 src/usr.bin/xlint/lint2/externs2.h cvs rdiff -u -r1.22 -r1.23 src/usr.bin/xlint/lint2/hash.c \ src/usr.bin/xlint/lint2/main2.c cvs rdiff -u -r1.67 -r1.68 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/externs2.h diff -u src/usr.bin/xlint/lint2/externs2.h:1.15 src/usr.bin/xlint/lint2/externs2.h:1.16 --- src/usr.bin/xlint/lint2/externs2.h:1.15 Sun Sep 5 18:17:15 2021 +++ src/usr.bin/xlint/lint2/externs2.h Tue Nov 16 22:03:12 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: externs2.h,v 1.15 2021/09/05 18:17:15 rillig Exp $ */ +/* $NetBSD: externs2.h,v 1.16 2021/11/16 22:03:12 rillig Exp $ */ /* * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. @@ -48,13 +48,13 @@ extern bool Fflag; /* * hash.c */ -extern void _inithash(hte_t ***); +extern hte_t** htab_new(void); extern hte_t *_hsearch(hte_t **, const char *, bool); +extern void symtab_init(void); extern void symtab_forall(void (*)(hte_t *)); -extern void _destroyhash(hte_t **); extern void symtab_forall_sorted(void (*)(hte_t *)); +extern void _destroyhash(hte_t **); -#define inithash() _inithash(NULL); #define hsearch(a, b) _hsearch(NULL, (a), (b)) /* Index: src/usr.bin/xlint/lint2/hash.c diff -u src/usr.bin/xlint/lint2/hash.c:1.22 src/usr.bin/xlint/lint2/hash.c:1.23 --- src/usr.bin/xlint/lint2/hash.c:1.22 Sat Aug 28 21:52:14 2021 +++ src/usr.bin/xlint/lint2/hash.c Tue Nov 16 22:03:12 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: hash.c,v 1.22 2021/08/28 21:52:14 rillig Exp $ */ +/* $NetBSD: hash.c,v 1.23 2021/11/16 22:03:12 rillig Exp $ */ /* * Copyright (c) 1994, 1995 Jochen Pohl @@ -37,7 +37,7 @@ #include #if defined(__RCSID) && !defined(lint) -__RCSID("$NetBSD: hash.c,v 1.22 2021/08/28 21:52:14 rillig Exp $"); +__RCSID("$NetBSD: hash.c,v 1.23 2021/11/16 22:03:12 rillig Exp $"); #endif /* @@ -57,14 +57,10 @@ static hte_t **htab; /* * Initialize hash table. */ -void -_inithash(hte_t ***tablep) +hte_t ** +htab_new(void) { - - if (tablep == NULL) - tablep = - - *tablep = xcalloc(HSHSIZ2, sizeof(**tablep)); + return xcalloc(HSHSIZ2, sizeof(*htab_new())); } /* @@ -151,6 +147,12 @@ hte_by_name(const void *va, const void * return strcmp(a->h_name, b->h_name); } +void +symtab_init(void) +{ + htab = htab_new(); +} + /* * Call the action for each name in the hash table. */ Index: src/usr.bin/xlint/lint2/main2.c diff -u src/usr.bin/xlint/lint2/main2.c:1.22 src/usr.bin/xlint/lint2/main2.c:1.23 --- src/usr.bin/xlint/lint2/main2.c:1.22 Sun Sep 5 18:17:15 2021 +++ src/usr.bin/xlint/lint2/main2.c Tue Nov 16 22:03:12 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: main2.c,v 1.22 2021/09/05 18:17:15 rillig Exp $ */ +/* $NetBSD: main2.c,v 1.23 2021/11/16 22:03:12 rillig Exp $ */ /* * Copyright (c) 1994, 1995 Jochen Pohl @@ -37,7 +37,7 @@ #include #if defined(__RCSID) && !defined(lint) -__RCSID("$NetBSD: main2.c,v 1.22 2021/09/05 18:17:15 rillig Exp $"); +__RCSID("$NetBSD: main2.c,v 1.23 2021/11/16 22:03:12 rillig Exp $"); #endif #include @@ -155,8 +155,7 @@ main(int argc, char *argv[]) initmem(); - /* initialize hash table */ - inithash(); + symtab_init(); for (i = 0; i < argc; i++) readfile(argv[i]); Index: src/usr.bin/xlint/lint2/read.c diff -u src/usr.bin/xlint/lint2/read.c:1.67 src/usr.bin/xlint/lint2/read.c:1.68 --- src/usr.bin/xlint/lint2/read.c:1.67 Sun Sep 5 19:58:53 2021 +++ src/usr.bin/xlint/lint2/read.c Tue Nov 16 22:03:12 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: read.c,v 1.67 2021/09/05 19:58:53 rillig Exp $ */ +/* $NetBSD: read.c,v 1.68 2021/11/16 22:03:12 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.67 2021/09/05 19:58:53 rillig Exp $"); +__RCSID("$NetBSD: read.c,v 1.68 2021/11/16 22:03:12 rillig Exp $"); #endif #include @@ -223,7 +223,7 @@ readfile(const char *name) if (thtab == NULL) thtab = xcalloc(THSHSIZ2, sizeof(*thtab)); - _inithash(); + renametab = htab_new(); srcfile = getfnidx(name);
CVS commit: src/usr.bin/xlint/lint2
Module Name:src Committed By: rillig Date: Tue Nov 16 22:03:12 UTC 2021 Modified Files: src/usr.bin/xlint/lint2: externs2.h hash.c main2.c read.c Log Message: lint: clean up initialization of lint2 symbol table No functional change. To generate a diff of this commit: cvs rdiff -u -r1.15 -r1.16 src/usr.bin/xlint/lint2/externs2.h cvs rdiff -u -r1.22 -r1.23 src/usr.bin/xlint/lint2/hash.c \ src/usr.bin/xlint/lint2/main2.c cvs rdiff -u -r1.67 -r1.68 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.
CVS commit: src/usr.bin/xlint/lint2
Module Name:src Committed By: rillig Date: Fri Sep 10 21:05:08 UTC 2021 Modified Files: src/usr.bin/xlint/lint2: check-msgs.lua Log Message: tests/lint: align message checker for lint2 to the one from lint1 No functional change. To generate a diff of this commit: cvs rdiff -u -r1.1 -r1.2 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. Modified files: Index: src/usr.bin/xlint/lint2/check-msgs.lua diff -u src/usr.bin/xlint/lint2/check-msgs.lua:1.1 src/usr.bin/xlint/lint2/check-msgs.lua:1.2 --- src/usr.bin/xlint/lint2/check-msgs.lua:1.1 Sun Feb 28 18:17:08 2021 +++ src/usr.bin/xlint/lint2/check-msgs.lua Fri Sep 10 21:05:08 2021 @@ -1,5 +1,5 @@ #! /usr/bin/lua --- $NetBSD: check-msgs.lua,v 1.1 2021/02/28 18:17:08 rillig Exp $ +-- $NetBSD: check-msgs.lua,v 1.2 2021/09/10 21:05:08 rillig Exp $ --[[ @@ -12,7 +12,7 @@ actual user-visible message text in msg. local function load_messages(fname) - local msgs = {} + local msgs = {} ---@type tablestring local f = assert(io.open(fname, "r")) for line in f:lines() do @@ -28,11 +28,19 @@ local function load_messages(fname) end -local function check_message(fname, lineno, id, comment, msgs, errors) +local had_errors = false +---@param fmt string +function print_error(fmt, ...) + print(fmt:format(...)) + had_errors = true +end + + +local function check_message(fname, lineno, id, comment, msgs) local msg = msgs[id] if msg == nil then -errors:add("%s:%d: id=%d not found", fname, lineno, id) +print_error("%s:%d: id=%d not found", fname, lineno, id) return end @@ -50,17 +58,12 @@ local function check_message(fname, line return end - errors:add("%s:%d: id=%-3d msg=%-40s comment=%s", + print_error("%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 function check_file(fname, msgs) local f = assert(io.open(fname, "r")) local lineno = 0 local prev = "" @@ -72,9 +75,9 @@ local function collect_errors(fname, msg if func == "msg" then local comment = prev:match("^%s+/%* (.+) %*/$") if comment ~= nil then -check_message(fname, lineno, id, comment, msgs, errors) +check_message(fname, lineno, id, comment, msgs) else -errors:add("%s:%d: missing comment for %d: /* %s */", +print_error("%s:%d: missing comment for %d: /* %s */", fname, lineno, id, msgs[id]) end end @@ -83,28 +86,15 @@ local function collect_errors(fname, msg 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 +check_file(fname, msgs) end - return ok end - -os.exit(main(arg)) +main(arg) +os.exit(not had_errors)
CVS commit: src/usr.bin/xlint/lint2
Module Name:src Committed By: rillig Date: Fri Sep 10 21:05:08 UTC 2021 Modified Files: src/usr.bin/xlint/lint2: check-msgs.lua Log Message: tests/lint: align message checker for lint2 to the one from lint1 No functional change. To generate a diff of this commit: cvs rdiff -u -r1.1 -r1.2 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.
CVS commit: src/usr.bin/xlint/lint2
Module Name:src Committed By: rillig Date: Sun Sep 5 19:58:53 UTC 2021 Modified Files: src/usr.bin/xlint/lint2: read.c Log Message: lint: remove source code references from internal error message The additional strings that are provided with the error message are distinctive enough. To generate a diff of this commit: cvs rdiff -u -r1.66 -r1.67 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.66 src/usr.bin/xlint/lint2/read.c:1.67 --- src/usr.bin/xlint/lint2/read.c:1.66 Sun Sep 5 19:44:56 2021 +++ src/usr.bin/xlint/lint2/read.c Sun Sep 5 19:58:53 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: read.c,v 1.66 2021/09/05 19:44:56 rillig Exp $ */ +/* $NetBSD: read.c,v 1.67 2021/09/05 19:58:53 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.66 2021/09/05 19:44:56 rillig Exp $"); +__RCSID("$NetBSD: read.c,v 1.67 2021/09/05 19:58:53 rillig Exp $"); #endif #include @@ -72,7 +72,7 @@ static size_t nfnames; /* * Types are shared (to save memory for the types itself) and accessed * via indices (to save memory for references to types (indices are short)). - * To share types, a equal type must be located fast. This is done by a + * To share types, an equal type must be located fast. This is done by a * hash table. Access by indices is done via an array of pointers to the * types. */ @@ -91,9 +91,8 @@ static hte_t **renametab; static int csrcfile; -#define inperr(fmt, args...) \ - inperror(__FILE__, __LINE__, fmt, ##args) -static void inperror(const char *, size_t, const char *, ...); +static void inperr(const char *, ...) +__attribute__((format(printf, 1, 2), noreturn)); static void setsrc(const char *); static void setfnid(int, const char *); static void funccall(pos_t *, const char *); @@ -243,8 +242,8 @@ readfile(const char *name) } -static void __attribute__((format(printf, 3, 4))) __attribute__((noreturn)) -inperror(const char *file, size_t line, const char *fmt, ...) +static void +inperr(const char *fmt, ...) { va_list ap; char buf[1024]; @@ -253,7 +252,7 @@ inperror(const char *file, size_t line, (void)vsnprintf(buf, sizeof(buf), fmt, ap); va_end(ap); - errx(1, "%s,%zu: input file error: %s,%zu (%s)", file, line, + errx(1, "input file error: %s,%zu (%s)", fnames[srcfile], flines[srcfile], buf); }
CVS commit: src/usr.bin/xlint/lint2
Module Name:src Committed By: rillig Date: Sun Sep 5 19:58:53 UTC 2021 Modified Files: src/usr.bin/xlint/lint2: read.c Log Message: lint: remove source code references from internal error message The additional strings that are provided with the error message are distinctive enough. To generate a diff of this commit: cvs rdiff -u -r1.66 -r1.67 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.
CVS commit: src/usr.bin/xlint/lint2
Module Name:src Committed By: rillig Date: Sun Sep 5 19:44:57 UTC 2021 Modified Files: src/usr.bin/xlint/lint2: read.c Log Message: lint: extract function for reading a single line from a .ln file No functional change. To generate a diff of this commit: cvs rdiff -u -r1.65 -r1.66 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.65 src/usr.bin/xlint/lint2/read.c:1.66 --- src/usr.bin/xlint/lint2/read.c:1.65 Sun Sep 5 16:15:05 2021 +++ src/usr.bin/xlint/lint2/read.c Sun Sep 5 19:44:56 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: read.c,v 1.65 2021/09/05 16:15:05 rillig Exp $ */ +/* $NetBSD: read.c,v 1.66 2021/09/05 19:44:56 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.65 2021/09/05 16:15:05 rillig Exp $"); +__RCSID("$NetBSD: read.c,v 1.66 2021/09/05 19:44:56 rillig Exp $"); #endif #include @@ -139,15 +139,79 @@ parse_short(const char **p) return (short)parse_int(p); } +static void +read_ln_line(char *line, size_t len) +{ + const char *cp; + int cline, isrc, iline; + char rt; + pos_t pos; + + flines[srcfile]++; + + if (len == 0 || line[len - 1] != '\n') + inperr("%s", [len - 1]); + line[len - 1] = '\0'; + cp = line; + + /* line number in csrcfile */ + if (!try_parse_int(, )) + cline = -1; + + /* record type */ + if (*cp == '\0') + inperr("missing record type"); + rt = *cp++; + + if (rt == 'S') { + setsrc(cp); + return; + } + if (rt == 's') { + setfnid(cline, cp); + return; + } + + /* + * Index of (included) source file. If this index is + * different from csrcfile, it refers to an included + * file. + */ + isrc = parse_int(); + isrc = inpfns[isrc]; + + /* line number in isrc */ + if (*cp++ != '.') + inperr("bad line number"); + iline = parse_int(); + + pos.p_src = (unsigned short)csrcfile; + pos.p_line = (unsigned short)cline; + pos.p_isrc = (unsigned short)isrc; + pos.p_iline = (unsigned short)iline; + + /* process rest of this record */ + switch (rt) { + case 'c': + funccall(, cp); + break; + case 'd': + decldef(, cp); + break; + case 'u': + usedsym(, cp); + break; + default: + inperr("bad record type %c", rt); + } +} + void readfile(const char *name) { FILE *inp; size_t len; - const char *cp; - char *line, rt = '\0'; - int cline, isrc, iline; - pos_t pos; + char *line; if (inpfns == NULL) inpfns = xcalloc(ninpfns = 128, sizeof(*inpfns)); @@ -167,65 +231,8 @@ readfile(const char *name) if ((inp = fopen(name, "r")) == NULL) err(1, "cannot open %s", name); - while ((line = fgetln(inp, )) != NULL) { - flines[srcfile]++; - - if (len == 0 || line[len - 1] != '\n') - inperr("%s", [len - 1]); - line[len - 1] = '\0'; - cp = line; - - /* line number in csrcfile */ - if (!try_parse_int(, )) - cline = -1; - - /* record type */ - if (*cp == '\0') - inperr("missing record type"); - rt = *cp++; - - if (rt == 'S') { - setsrc(cp); - continue; - } else if (rt == 's') { - setfnid(cline, cp); - continue; - } - - /* - * Index of (included) source file. If this index is - * different from csrcfile, it refers to an included - * file. - */ - isrc = parse_int(); - isrc = inpfns[isrc]; - - /* line number in isrc */ - if (*cp++ != '.') - inperr("bad line number"); - iline = parse_int(); - - pos.p_src = (unsigned short)csrcfile; - pos.p_line = (unsigned short)cline; - pos.p_isrc = (unsigned short)isrc; - pos.p_iline = (unsigned short)iline; - - /* process rest of this record */ - switch (rt) { - case 'c': - funccall(, cp); - break; - case 'd': - decldef(, cp); - break; - case 'u': - usedsym(, cp); - break; - default: - inperr("bad record type %c", rt); - } - - } + while ((line = fgetln(inp, )) != NULL) + read_ln_line(line, len); _destroyhash(renametab);
CVS commit: src/usr.bin/xlint/lint2
Module Name:src Committed By: rillig Date: Sun Sep 5 19:44:57 UTC 2021 Modified Files: src/usr.bin/xlint/lint2: read.c Log Message: lint: extract function for reading a single line from a .ln file No functional change. To generate a diff of this commit: cvs rdiff -u -r1.65 -r1.66 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.
CVS commit: src/usr.bin/xlint/lint2
Module Name:src Committed By: rillig Date: Sat Sep 4 19:16:38 UTC 2021 Modified Files: src/usr.bin/xlint/lint2: read.c Log Message: lint: reduce complexity of reading a function call No functional change. To generate a diff of this commit: cvs rdiff -u -r1.63 -r1.64 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.63 src/usr.bin/xlint/lint2/read.c:1.64 --- src/usr.bin/xlint/lint2/read.c:1.63 Mon Aug 30 21:35:23 2021 +++ src/usr.bin/xlint/lint2/read.c Sat Sep 4 19:16:38 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: read.c,v 1.63 2021/08/30 21:35:23 rillig Exp $ */ +/* $NetBSD: read.c,v 1.64 2021/09/04 19:16:38 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.63 2021/08/30 21:35:23 rillig Exp $"); +__RCSID("$NetBSD: read.c,v 1.64 2021/09/04 19:16:38 rillig Exp $"); #endif #include @@ -307,45 +307,47 @@ funccall(pos_t *posp, const char *cp) /* read flags */ rused = rdisc = false; lai = >f_args; - while ((c = *cp) == 'u' || c == 'i' || c == 'd' || - c == 'z' || c == 'p' || c == 'n' || c == 's') { - cp++; - switch (c) { - case 'u': - if (rused || rdisc) -inperr("used or discovered: %c", c); - rused = true; - break; - case 'i': - if (rused || rdisc) -inperr("used or discovered: %c", c); - break; - case 'd': - if (rused || rdisc) -inperr("used or discovered: %c", c); - rdisc = true; - break; - case 'z': - case 'p': - case 'n': - case 's': - ai = xalloc(sizeof(*ai)); - ai->a_num = parse_int(); - if (c == 'z') { -ai->a_pcon = ai->a_zero = true; - } else if (c == 'p') { -ai->a_pcon = true; - } else if (c == 'n') { -ai->a_ncon = true; - } else { -ai->a_fmt = true; -ai->a_fstrg = inpqstrg(cp, ); - } - *lai = ai; - lai = >a_next; - break; + +again: + c = *cp++; + switch (c) { + case 'u': + if (rused || rdisc) + inperr("used or discovered: %c", c); + rused = true; + goto again; + case 'i': + if (rused || rdisc) + inperr("used or discovered: %c", c); + goto again; + case 'd': + if (rused || rdisc) + inperr("used or discovered: %c", c); + rdisc = true; + goto again; + case 'z': + case 'p': + case 'n': + case 's': + ai = xalloc(sizeof(*ai)); + ai->a_num = parse_int(); + if (c == 'z') { + ai->a_pcon = ai->a_zero = true; + } else if (c == 'p') { + ai->a_pcon = true; + } else if (c == 'n') { + ai->a_ncon = true; + } else { + ai->a_fmt = true; + ai->a_fstrg = inpqstrg(cp, ); } + *lai = ai; + lai = >a_next; + goto again; + default: + cp--; } + fcall->f_rused = rused; fcall->f_rdisc = rdisc;
CVS commit: src/usr.bin/xlint/lint2
Module Name:src Committed By: rillig Date: Sat Sep 4 19:16:38 UTC 2021 Modified Files: src/usr.bin/xlint/lint2: read.c Log Message: lint: reduce complexity of reading a function call No functional change. To generate a diff of this commit: cvs rdiff -u -r1.63 -r1.64 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.
CVS commit: src/usr.bin/xlint/lint2
Module Name:src Committed By: rillig Date: Sat Sep 4 18:49:33 UTC 2021 Modified Files: src/usr.bin/xlint/lint2: emit2.c Log Message: lint: condense code for writing to a lint library Same as in lint1. No functional change. To generate a diff of this commit: cvs rdiff -u -r1.24 -r1.25 src/usr.bin/xlint/lint2/emit2.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/emit2.c diff -u src/usr.bin/xlint/lint2/emit2.c:1.24 src/usr.bin/xlint/lint2/emit2.c:1.25 --- src/usr.bin/xlint/lint2/emit2.c:1.24 Sat Sep 4 14:26:32 2021 +++ src/usr.bin/xlint/lint2/emit2.c Sat Sep 4 18:49:33 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: emit2.c,v 1.24 2021/09/04 14:26:32 rillig Exp $ */ +/* $NetBSD: emit2.c,v 1.25 2021/09/04 18:49:33 rillig Exp $ */ /* * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. @@ -34,7 +34,7 @@ #include #if defined(__RCSID) && !defined(lint) -__RCSID("$NetBSD: emit2.c,v 1.24 2021/09/04 14:26:32 rillig Exp $"); +__RCSID("$NetBSD: emit2.c,v 1.25 2021/09/04 18:49:33 rillig Exp $"); #endif #include "lint2.h" @@ -55,54 +55,28 @@ outtype(type_t *tp) tspec_t ts; type_t **ap; +#ifdef INT128_SIZE + static const char tt[NTSPEC] = "???BCCCSSIILLQQJJDDDVTTTPAF?XXX"; + static const char ss[NTSPEC] = "??? su u u u u us l sue ?s l"; +#else + static const char tt[NTSPEC] = "???BCCCSSIILLQQDDDVTTTPAF?XXX"; + static const char ss[NTSPEC] = "??? su u u u us l sue ?s l"; +#endif + while (tp != NULL) { if ((ts = tp->t_tspec) == INT && tp->t_is_enum) ts = ENUM; - switch (ts) { - case BOOL: t = 'B'; s = '\0'; break; - case CHAR: t = 'C'; s = '\0'; break; - case SCHAR: t = 'C'; s = 's'; break; - case UCHAR: t = 'C'; s = 'u'; break; - case SHORT: t = 'S'; s = '\0'; break; - case USHORT: t = 'S'; s = 'u'; break; - case INT: t = 'I'; s = '\0'; break; - case UINT: t = 'I'; s = 'u'; break; - case LONG: t = 'L'; s = '\0'; break; - case ULONG: t = 'L'; s = 'u'; break; - case QUAD: t = 'Q'; s = '\0'; break; - case UQUAD: t = 'Q'; s = 'u'; break; -#ifdef INT128_SIZE - case INT128: t = 'J'; s = '\0'; break; - case UINT128: t = 'J'; s = 'u'; break; -#endif - case FLOAT: t = 'D'; s = 's'; break; - case DOUBLE: t = 'D'; s = '\0'; break; - case LDOUBLE: t = 'D'; s = 'l'; break; - case VOID: t = 'V'; s = '\0'; break; - case PTR: t = 'P'; s = '\0'; break; - case ARRAY: t = 'A'; s = '\0'; break; - case ENUM: t = 'T'; s = 'e'; break; - case STRUCT: t = 'T'; s = 's'; break; - case UNION: t = 'T'; s = 'u'; break; - case FCOMPLEX: t = 'X'; s = 's'; break; - case DCOMPLEX: t = 'X'; s = '\0'; break; - case LCOMPLEX: t = 'X'; s = 'l'; break; - case FUNC: - if (tp->t_args != NULL && !tp->t_proto) { -t = 'f'; - } else { -t = 'F'; - } - s = '\0'; - break; - default: - errx(1, "internal error: outtype() 1"); - } + t = tt[ts]; + s = ss[ts]; + if (!ch_isupper(t)) + errx(1, "internal error: outtype(%d)", ts); + if (ts == FUNC && tp->t_args != NULL && !tp->t_proto) + t = 'f'; if (tp->t_const) outchar('c'); if (tp->t_volatile) outchar('v'); - if (s != '\0') + if (s != ' ') outchar(s); outchar(t); if (ts == ARRAY) {
CVS commit: src/usr.bin/xlint/lint2
Module Name:src Committed By: rillig Date: Sat Sep 4 18:49:33 UTC 2021 Modified Files: src/usr.bin/xlint/lint2: emit2.c Log Message: lint: condense code for writing to a lint library Same as in lint1. No functional change. To generate a diff of this commit: cvs rdiff -u -r1.24 -r1.25 src/usr.bin/xlint/lint2/emit2.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/usr.bin/xlint/lint2
Module Name:src Committed By: rillig Date: Mon Aug 30 21:35:23 UTC 2021 Modified Files: src/usr.bin/xlint/lint2: read.c Log Message: lint: extract parse_function_attribute from decldef No functional change. To generate a diff of this commit: cvs rdiff -u -r1.62 -r1.63 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.
CVS commit: src/usr.bin/xlint/lint2
Module Name:src Committed By: rillig Date: Mon Aug 30 21:35:23 UTC 2021 Modified Files: src/usr.bin/xlint/lint2: read.c Log Message: lint: extract parse_function_attribute from decldef No functional change. To generate a diff of this commit: cvs rdiff -u -r1.62 -r1.63 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.62 src/usr.bin/xlint/lint2/read.c:1.63 --- src/usr.bin/xlint/lint2/read.c:1.62 Mon Aug 30 20:20:20 2021 +++ src/usr.bin/xlint/lint2/read.c Mon Aug 30 21:35:23 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: read.c,v 1.62 2021/08/30 20:20:20 rillig Exp $ */ +/* $NetBSD: read.c,v 1.63 2021/08/30 21:35:23 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.62 2021/08/30 20:20:20 rillig Exp $"); +__RCSID("$NetBSD: read.c,v 1.63 2021/08/30 21:35:23 rillig Exp $"); #endif #include @@ -369,6 +369,76 @@ funccall(pos_t *posp, const char *cp) inperr("trailing line data: %s", cp); } +static bool +parse_function_attribute(const char **pp, sym_t *sym, bool *used) +{ + + switch (*(*pp)++) { + case 'd': + if (sym->s_def != NODECL) + inperr("def"); + sym->s_def = DEF; + break; + case 'e': + if (sym->s_def != NODECL) + inperr("decl"); + sym->s_def = DECL; + break; + case 'i': + if (sym->s_inline) + inperr("inline"); + sym->s_inline = true; + break; + case 'o': + if (sym->s_old_style_function) + inperr("osdef"); + sym->s_old_style_function = true; + break; + case 'r': + if (sym->s_function_has_return_value) + inperr("r"); + sym->s_function_has_return_value = true; + break; + case 's': + if (sym->s_static) + inperr("static"); + sym->s_static = true; + break; + case 't': + if (sym->s_def != NODECL) + inperr("tdef"); + sym->s_def = TDEF; + break; + case 'u': + if (*used) + inperr("used"); + *used = true; + break; + case 'v': + if (sym->s_check_only_first_args) + inperr("v"); + sym->s_check_only_first_args = true; + sym->s_check_num_args = parse_short(pp); + break; + case 'P': + if (sym->s_printflike) + inperr("P"); + sym->s_printflike = true; + sym->s_printflike_arg = parse_short(pp); + break; + case 'S': + if (sym->s_scanflike) + inperr("S"); + sym->s_scanflike = true; + sym->s_scanflike_arg = parse_short(pp); + break; + default: + (*pp)--; + return false; + } + return true; +} + /* * Process a declaration or definition (d-record). */ @@ -376,7 +446,7 @@ static void decldef(pos_t *posp, const char *cp) { sym_t *symp, sym; - char c, *pos1, *tname; + char *pos1, *tname; bool used, renamed; hte_t *hte, *renamehte = NULL; const char *name, *newname; @@ -387,73 +457,9 @@ decldef(pos_t *posp, const char *cp) used = false; - for (;;) { - switch (c = *cp++) { - case 'd': - if (sym.s_def != NODECL) -inperr("def"); - sym.s_def = DEF; - break; - case 'e': - if (sym.s_def != NODECL) -inperr("decl"); - sym.s_def = DECL; - break; - case 'i': - if (sym.s_inline) -inperr("inline"); - sym.s_inline = true; - break; - case 'o': - if (sym.s_old_style_function) -inperr("osdef"); - sym.s_old_style_function = true; - break; - case 'r': - if (sym.s_function_has_return_value) -inperr("r"); - sym.s_function_has_return_value = true; - break; - case 's': - if (sym.s_static) -inperr("static"); - sym.s_static = true; - break; - case 't': - if (sym.s_def != NODECL) -inperr("tdef"); - sym.s_def = TDEF; - break; - case 'u': - if (used) -inperr("used"); - used = true; - break; - case 'v': - if (sym.s_check_only_first_args) -inperr("v"); - sym.s_check_only_first_args = true; - sym.s_check_num_args = parse_short(); - break; - case 'P': - if (sym.s_printflike) -inperr("P"); - sym.s_printflike = true; - sym.s_printflike_arg = parse_short(); - break; - case 'S': - if (sym.s_scanflike) -inperr("S"); - sym.s_scanflike = true; - sym.s_scanflike_arg = parse_short(); - break; - default: - cp--; - goto done_function_attributes; - } - } + while (parse_function_attribute(, , )) + continue; -done_function_attributes: /* read symbol name, doing renaming if necessary */ name = inpname(cp, ); renamed = false;
CVS commit: src/usr.bin/xlint/lint2
Module Name:src Committed By: rillig Date: Mon Aug 30 20:20:20 UTC 2021 Modified Files: src/usr.bin/xlint/lint2: read.c Log Message: lint: remove redundant call to strchr in decldef This time, the branches for varargs, printflike and scanflike in the big switch statement are covered by unit tests. These tests would have caught the previous "cleanup" that broke parsing of these function attributes. Furthermore, this second cleanup is closer to the original code and conceptually simpler since it avoids having many 'continue' statements in a 'switch' statement, which would have been unusual. The branches for inline functions and used functions are still not covered by the tests, but they are structurally equal to several other branches. No functional change. To generate a diff of this commit: cvs rdiff -u -r1.61 -r1.62 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.61 src/usr.bin/xlint/lint2/read.c:1.62 --- src/usr.bin/xlint/lint2/read.c:1.61 Mon Aug 30 19:07:57 2021 +++ src/usr.bin/xlint/lint2/read.c Mon Aug 30 20:20:20 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: read.c,v 1.61 2021/08/30 19:07:57 rillig Exp $ */ +/* $NetBSD: read.c,v 1.62 2021/08/30 20:20:20 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.61 2021/08/30 19:07:57 rillig Exp $"); +__RCSID("$NetBSD: read.c,v 1.62 2021/08/30 20:20:20 rillig Exp $"); #endif #include @@ -387,9 +387,8 @@ decldef(pos_t *posp, const char *cp) used = false; - while (strchr("deiorstuvPS", (c = *cp)) != NULL) { - cp++; - switch (c) { + for (;;) { + switch (c = *cp++) { case 'd': if (sym.s_def != NODECL) inperr("def"); @@ -448,9 +447,13 @@ decldef(pos_t *posp, const char *cp) sym.s_scanflike = true; sym.s_scanflike_arg = parse_short(); break; + default: + cp--; + goto done_function_attributes; } } +done_function_attributes: /* read symbol name, doing renaming if necessary */ name = inpname(cp, ); renamed = false;
CVS commit: src/usr.bin/xlint/lint2
Module Name:src Committed By: rillig Date: Mon Aug 30 20:20:20 UTC 2021 Modified Files: src/usr.bin/xlint/lint2: read.c Log Message: lint: remove redundant call to strchr in decldef This time, the branches for varargs, printflike and scanflike in the big switch statement are covered by unit tests. These tests would have caught the previous "cleanup" that broke parsing of these function attributes. Furthermore, this second cleanup is closer to the original code and conceptually simpler since it avoids having many 'continue' statements in a 'switch' statement, which would have been unusual. The branches for inline functions and used functions are still not covered by the tests, but they are structurally equal to several other branches. No functional change. To generate a diff of this commit: cvs rdiff -u -r1.61 -r1.62 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.
CVS commit: src/usr.bin/xlint/lint2
Module Name:src Committed By: christos Date: Mon Aug 30 18:03:52 UTC 2021 Modified Files: src/usr.bin/xlint/lint2: read.c Log Message: Move the character one back so that we don't increment twice To generate a diff of this commit: cvs rdiff -u -r1.59 -r1.60 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.59 src/usr.bin/xlint/lint2/read.c:1.60 --- src/usr.bin/xlint/lint2/read.c:1.59 Mon Aug 30 10:57:04 2021 +++ src/usr.bin/xlint/lint2/read.c Mon Aug 30 14:03:52 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: read.c,v 1.59 2021/08/30 14:57:04 christos Exp $ */ +/* $NetBSD: read.c,v 1.60 2021/08/30 18:03:52 christos 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.59 2021/08/30 14:57:04 christos Exp $"); +__RCSID("$NetBSD: read.c,v 1.60 2021/08/30 18:03:52 christos Exp $"); #endif #include @@ -137,8 +137,11 @@ static short parse_short(const char **p) { + short s; (*p)++; - return (short)parse_int(p); + s = (short)parse_int(p); + (*p)--; + return s; } void
CVS commit: src/usr.bin/xlint/lint2
Module Name:src Committed By: christos Date: Mon Aug 30 18:03:52 UTC 2021 Modified Files: src/usr.bin/xlint/lint2: read.c Log Message: Move the character one back so that we don't increment twice To generate a diff of this commit: cvs rdiff -u -r1.59 -r1.60 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.
CVS commit: src/usr.bin/xlint/lint2
Module Name:src Committed By: christos Date: Mon Aug 30 14:57:04 UTC 2021 Modified Files: src/usr.bin/xlint/lint2: read.c Log Message: Skip the current character before parsing the number of arguments. To generate a diff of this commit: cvs rdiff -u -r1.58 -r1.59 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.58 src/usr.bin/xlint/lint2/read.c:1.59 --- src/usr.bin/xlint/lint2/read.c:1.58 Sun Aug 29 06:18:17 2021 +++ src/usr.bin/xlint/lint2/read.c Mon Aug 30 10:57:04 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: read.c,v 1.58 2021/08/29 10:18:17 rillig Exp $ */ +/* $NetBSD: read.c,v 1.59 2021/08/30 14:57:04 christos 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.58 2021/08/29 10:18:17 rillig Exp $"); +__RCSID("$NetBSD: read.c,v 1.59 2021/08/30 14:57:04 christos Exp $"); #endif #include @@ -137,6 +137,7 @@ static short parse_short(const char **p) { + (*p)++; return (short)parse_int(p); }
CVS commit: src/usr.bin/xlint/lint2
Module Name:src Committed By: christos Date: Mon Aug 30 14:57:04 UTC 2021 Modified Files: src/usr.bin/xlint/lint2: read.c Log Message: Skip the current character before parsing the number of arguments. To generate a diff of this commit: cvs rdiff -u -r1.58 -r1.59 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.
CVS commit: src/usr.bin/xlint/lint2
Module Name:src Committed By: rillig Date: Sun Aug 29 10:18:17 UTC 2021 Modified Files: src/usr.bin/xlint/lint2: read.c Log Message: lint: remove redundant call to strchr To generate a diff of this commit: cvs rdiff -u -r1.57 -r1.58 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.
CVS commit: src/usr.bin/xlint/lint2
Module Name:src Committed By: rillig Date: Sun Aug 29 10:18:17 UTC 2021 Modified Files: src/usr.bin/xlint/lint2: read.c Log Message: lint: remove redundant call to strchr To generate a diff of this commit: cvs rdiff -u -r1.57 -r1.58 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.57 src/usr.bin/xlint/lint2/read.c:1.58 --- src/usr.bin/xlint/lint2/read.c:1.57 Sun Aug 29 10:13:02 2021 +++ src/usr.bin/xlint/lint2/read.c Sun Aug 29 10:18:17 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: read.c,v 1.57 2021/08/29 10:13:02 rillig Exp $ */ +/* $NetBSD: read.c,v 1.58 2021/08/29 10:18:17 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.57 2021/08/29 10:13:02 rillig Exp $"); +__RCSID("$NetBSD: read.c,v 1.58 2021/08/29 10:18:17 rillig Exp $"); #endif #include @@ -388,68 +388,68 @@ decldef(pos_t *posp, const char *cp) used = false; - while (strchr("deiorstuvPS", (c = *cp)) != NULL) { - cp++; + for (; (c = *cp) != '\0'; cp++) { switch (c) { case 'd': if (sym.s_def != NODECL) inperr("def"); sym.s_def = DEF; - break; + continue; case 'e': if (sym.s_def != NODECL) inperr("decl"); sym.s_def = DECL; - break; + continue; case 'i': if (sym.s_inline) inperr("inline"); sym.s_inline = true; - break; + continue; case 'o': if (sym.s_old_style_function) inperr("osdef"); sym.s_old_style_function = true; - break; + continue; case 'r': if (sym.s_function_has_return_value) inperr("r"); sym.s_function_has_return_value = true; - break; + continue; case 's': if (sym.s_static) inperr("static"); sym.s_static = true; - break; + continue; case 't': if (sym.s_def != NODECL) inperr("tdef"); sym.s_def = TDEF; - break; + continue; case 'u': if (used) inperr("used"); used = true; - break; + continue; case 'v': if (sym.s_check_only_first_args) inperr("v"); sym.s_check_only_first_args = true; sym.s_check_num_args = parse_short(); - break; + continue; case 'P': if (sym.s_printflike) inperr("P"); sym.s_printflike = true; sym.s_printflike_arg = parse_short(); - break; + continue; case 'S': if (sym.s_scanflike) inperr("S"); sym.s_scanflike = true; sym.s_scanflike_arg = parse_short(); - break; + continue; } + break; } /* read symbol name, doing renaming if necessary */
CVS commit: src/usr.bin/xlint/lint2
Module Name:src Committed By: rillig Date: Sun Aug 29 10:13:02 UTC 2021 Modified Files: src/usr.bin/xlint/lint2: chk.c emit2.c lint2.h read.c Log Message: lint: un-abbreviate members of sym_t No functional change. To generate a diff of this commit: cvs rdiff -u -r1.44 -r1.45 src/usr.bin/xlint/lint2/chk.c cvs rdiff -u -r1.22 -r1.23 src/usr.bin/xlint/lint2/emit2.c cvs rdiff -u -r1.18 -r1.19 src/usr.bin/xlint/lint2/lint2.h cvs rdiff -u -r1.56 -r1.57 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.44 src/usr.bin/xlint/lint2/chk.c:1.45 --- src/usr.bin/xlint/lint2/chk.c:1.44 Sun Aug 22 04:43:44 2021 +++ src/usr.bin/xlint/lint2/chk.c Sun Aug 29 10:13:02 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: chk.c,v 1.44 2021/08/22 04:43:44 rillig Exp $ */ +/* $NetBSD: chk.c,v 1.45 2021/08/29 10:13:02 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.44 2021/08/22 04:43:44 rillig Exp $"); +__RCSID("$NetBSD: chk.c,v 1.45 2021/08/29 10:13:02 rillig Exp $"); #endif #include @@ -382,7 +382,8 @@ chkfaui(const hte_t *hte, sym_t *def, sy ap2 = tp2->t_args; n = 0; while (*ap1 != NULL && *ap2 != NULL) { - if (def != NULL && def->s_va && n >= def->s_nva) + if (def != NULL && def->s_check_only_first_args && + n >= def->s_check_num_args) break; n++; chkau(hte, n, def, decl, pos1p, call1, call, @@ -392,7 +393,8 @@ chkfaui(const hte_t *hte, sym_t *def, sy } if (*ap1 == *ap2) { /* equal # of arguments */ - } else if (def != NULL && def->s_va && n >= def->s_nva) { + } else if (def != NULL && def->s_check_only_first_args && + n >= def->s_check_num_args) { /* * function definition with VARARGS; The # of * arguments of the call must be at least as large @@ -413,16 +415,18 @@ chkfaui(const hte_t *hte, sym_t *def, sy } /* perform SCANFLIKE/PRINTFLIKE tests */ - if (def == NULL || (!def->s_prfl && !def->s_scfl)) + if (def == NULL || (!def->s_printflike && !def->s_scanflike)) continue; - as = def->s_prfl ? def->s_nprfl : def->s_nscfl; + as = def->s_printflike + ? def->s_printflike_arg + : def->s_scanflike_arg; for (ai = call->f_args; ai != NULL; ai = ai->a_next) { if (ai->a_num == as) break; } if (ai == NULL || !ai->a_fmt) continue; - if (def->s_prfl) { + if (def->s_printflike) { printflike(hte, call, n, ai->a_fstrg, ap2); } else { scanflike(hte, call, n, ai->a_fstrg, ap2); @@ -463,7 +467,7 @@ chkau(const hte_t *hte, int n, sym_t *de */ /* arg1 must be promoted if it stems from an old style definition */ - promote = def != NULL && def->s_osdef; + promote = def != NULL && def->s_old_style_function; /* * If we compare with a definition or declaration, we must perform @@ -1078,7 +1082,7 @@ chkrvu(const hte_t *hte, sym_t *def) if (hte->h_calls == NULL) return; - if (def->s_rval) { + if (def->s_function_has_return_value) { /* * XXX as soon as we are able to disable single warnings * the following dependencies from hflag should be removed. @@ -1130,7 +1134,7 @@ chkadecl(const hte_t *hte, sym_t *def, s osdef = false; if (def != NULL) { - osdef = def->s_osdef; + osdef = def->s_old_style_function; sym1 = def; } else if (decl != NULL && TP(decl->s_type)->t_proto) { sym1 = decl; @@ -1173,8 +1177,8 @@ chkadecl(const hte_t *hte, sym_t *def, s tp2 = TP(sym->s_type); if (tp1->t_vararg == tp2->t_vararg) continue; - if (tp2->t_vararg && - sym1->s_va && sym1->s_nva == n && !sflag) { + if (tp2->t_vararg && sym1->s_check_only_first_args && + sym1->s_check_num_args == n && !sflag) { continue; } } Index: src/usr.bin/xlint/lint2/emit2.c diff -u src/usr.bin/xlint/lint2/emit2.c:1.22 src/usr.bin/xlint/lint2/emit2.c:1.23 --- src/usr.bin/xlint/lint2/emit2.c:1.22 Sat Aug 28 17:18:42 2021 +++ src/usr.bin/xlint/lint2/emit2.c Sun Aug 29 10:13:02 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: emit2.c,v 1.22 2021/08/28 17:18:42 rillig Exp $ */ +/* $NetBSD: emit2.c,v 1.23 2021/08/29 10:13:02 rillig Exp $ */ /* * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. @@ -34,7 +34,7 @@ #include #if defined(__RCSID) && !defined(lint) -__RCSID("$NetBSD: emit2.c,v 1.22 2021/08/28 17:18:42 rillig Exp $"); +__RCSID("$NetBSD: emit2.c,v 1.23 2021/08/29 10:13:02 rillig Exp $"); #endif #include "lint2.h" @@ -160,25 +160,25 @@ outdef(hte_t *hte, sym_t *sym) outint(0); /* flags */ - if (sym->s_va) { - outchar('v'); /* varargs */ - outint(sym->s_nva); + if (sym->s_check_only_first_args) { + outchar('v'); + outint(sym->s_check_num_args); } - if (sym->s_scfl) { - outchar('S'); /* scanflike */ -
CVS commit: src/usr.bin/xlint/lint2
Module Name:src Committed By: rillig Date: Sun Aug 29 10:13:02 UTC 2021 Modified Files: src/usr.bin/xlint/lint2: chk.c emit2.c lint2.h read.c Log Message: lint: un-abbreviate members of sym_t No functional change. To generate a diff of this commit: cvs rdiff -u -r1.44 -r1.45 src/usr.bin/xlint/lint2/chk.c cvs rdiff -u -r1.22 -r1.23 src/usr.bin/xlint/lint2/emit2.c cvs rdiff -u -r1.18 -r1.19 src/usr.bin/xlint/lint2/lint2.h cvs rdiff -u -r1.56 -r1.57 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.
CVS commit: src/usr.bin/xlint/lint2
Module Name:src Committed By: rillig Date: Sun Aug 29 09:48:02 UTC 2021 Modified Files: src/usr.bin/xlint/lint2: lint2.h Log Message: lint: in debug mode, use proper type for sym_t.s_def To generate a diff of this commit: cvs rdiff -u -r1.17 -r1.18 src/usr.bin/xlint/lint2/lint2.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/usr.bin/xlint/lint2
Module Name:src Committed By: rillig Date: Sun Aug 29 09:48:02 UTC 2021 Modified Files: src/usr.bin/xlint/lint2: lint2.h Log Message: lint: in debug mode, use proper type for sym_t.s_def To generate a diff of this commit: cvs rdiff -u -r1.17 -r1.18 src/usr.bin/xlint/lint2/lint2.h 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/lint2.h diff -u src/usr.bin/xlint/lint2/lint2.h:1.17 src/usr.bin/xlint/lint2/lint2.h:1.18 --- src/usr.bin/xlint/lint2/lint2.h:1.17 Sat Aug 28 12:21:53 2021 +++ src/usr.bin/xlint/lint2/lint2.h Sun Aug 29 09:48:02 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: lint2.h,v 1.17 2021/08/28 12:21:53 rillig Exp $ */ +/* $NetBSD: lint2.h,v 1.18 2021/08/29 09:48:02 rillig Exp $ */ /* * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. @@ -114,7 +114,7 @@ typedef struct { typedef struct sym { struct { pos_t s_pos; /* pos of def./decl. */ -#ifndef lint +#if !defined(lint) && !defined(DEBUG) unsigned char s_def; /* DECL, TDEF or DEF */ #else def_t s_def;
CVS commit: src/usr.bin/xlint/lint2
Module Name:src Committed By: rillig Date: Sat Aug 28 19:00:55 UTC 2021 Modified Files: src/usr.bin/xlint/lint2: hash.c Log Message: lint: fix memory leak in symtab_forall_sorted (since today) To generate a diff of this commit: cvs rdiff -u -r1.19 -r1.20 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.19 src/usr.bin/xlint/lint2/hash.c:1.20 --- src/usr.bin/xlint/lint2/hash.c:1.19 Sat Aug 28 17:18:42 2021 +++ src/usr.bin/xlint/lint2/hash.c Sat Aug 28 19:00:55 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: hash.c,v 1.19 2021/08/28 17:18:42 rillig Exp $ */ +/* $NetBSD: hash.c,v 1.20 2021/08/28 19:00:55 rillig Exp $ */ /* * Copyright (c) 1994, 1995 Jochen Pohl @@ -37,7 +37,7 @@ #include #if defined(__RCSID) && !defined(lint) -__RCSID("$NetBSD: hash.c,v 1.19 2021/08/28 17:18:42 rillig Exp $"); +__RCSID("$NetBSD: hash.c,v 1.20 2021/08/28 19:00:55 rillig Exp $"); #endif /* @@ -169,7 +169,6 @@ symtab_forall(void (*action)(hte_t *)) } } - /* Run the action for each name in the symbol table, in alphabetic order. */ void symtab_forall_sorted(void (*action)(hte_t *)) @@ -187,6 +186,8 @@ symtab_forall_sorted(void (*action)(hte_ for (i = 0; i < sorted.len; i++) action(sorted.items[i]); + + free(sorted.items); } /*
CVS commit: src/usr.bin/xlint/lint2
Module Name:src Committed By: rillig Date: Sat Aug 28 19:00:55 UTC 2021 Modified Files: src/usr.bin/xlint/lint2: hash.c Log Message: lint: fix memory leak in symtab_forall_sorted (since today) To generate a diff of this commit: cvs rdiff -u -r1.19 -r1.20 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.
CVS commit: src/usr.bin/xlint/lint2
Module Name:src Committed By: rillig Date: Sat Aug 28 17:11:19 UTC 2021 Modified Files: src/usr.bin/xlint/lint2: emit2.c externs2.h hash.c main2.c Log Message: lint: remove unused parameter from forall No functional change. To generate a diff of this commit: cvs rdiff -u -r1.20 -r1.21 src/usr.bin/xlint/lint2/emit2.c cvs rdiff -u -r1.12 -r1.13 src/usr.bin/xlint/lint2/externs2.h cvs rdiff -u -r1.17 -r1.18 src/usr.bin/xlint/lint2/hash.c cvs rdiff -u -r1.19 -r1.20 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/emit2.c diff -u src/usr.bin/xlint/lint2/emit2.c:1.20 src/usr.bin/xlint/lint2/emit2.c:1.21 --- src/usr.bin/xlint/lint2/emit2.c:1.20 Tue Aug 24 21:30:52 2021 +++ src/usr.bin/xlint/lint2/emit2.c Sat Aug 28 17:11:19 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: emit2.c,v 1.20 2021/08/24 21:30:52 rillig Exp $ */ +/* $NetBSD: emit2.c,v 1.21 2021/08/28 17:11:19 rillig Exp $ */ /* * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. @@ -34,7 +34,7 @@ #include #if defined(__RCSID) && !defined(lint) -__RCSID("$NetBSD: emit2.c,v 1.20 2021/08/24 21:30:52 rillig Exp $"); +__RCSID("$NetBSD: emit2.c,v 1.21 2021/08/28 17:11:19 rillig Exp $"); #endif #include "lint2.h" @@ -246,7 +246,7 @@ outlib(const char *name) outfiles(); /* write all definitions with external linkage */ - forall(dumpname); + symtab_forall(dumpname); /* close the output */ outclose(); Index: src/usr.bin/xlint/lint2/externs2.h diff -u src/usr.bin/xlint/lint2/externs2.h:1.12 src/usr.bin/xlint/lint2/externs2.h:1.13 --- src/usr.bin/xlint/lint2/externs2.h:1.12 Sun Aug 22 14:50:06 2021 +++ src/usr.bin/xlint/lint2/externs2.h Sat Aug 28 17:11:19 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: externs2.h,v 1.12 2021/08/22 14:50:06 rillig Exp $ */ +/* $NetBSD: externs2.h,v 1.13 2021/08/28 17:11:19 rillig Exp $ */ /* * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. @@ -52,12 +52,11 @@ extern bool Tflag; */ extern void _inithash(hte_t ***); extern hte_t *_hsearch(hte_t **, const char *, bool); -extern void _forall(hte_t **, void (*)(hte_t *)); +extern void symtab_forall(void (*)(hte_t *)); extern void _destroyhash(hte_t **); #define inithash() _inithash(NULL); #define hsearch(a, b) _hsearch(NULL, (a), (b)) -#define forall(a) _forall(NULL, (a)) /* * read.c Index: src/usr.bin/xlint/lint2/hash.c diff -u src/usr.bin/xlint/lint2/hash.c:1.17 src/usr.bin/xlint/lint2/hash.c:1.18 --- src/usr.bin/xlint/lint2/hash.c:1.17 Sat Aug 28 12:21:53 2021 +++ src/usr.bin/xlint/lint2/hash.c Sat Aug 28 17:11:19 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: hash.c,v 1.17 2021/08/28 12:21:53 rillig Exp $ */ +/* $NetBSD: hash.c,v 1.18 2021/08/28 17:11:19 rillig Exp $ */ /* * Copyright (c) 1994, 1995 Jochen Pohl @@ -37,7 +37,7 @@ #include #if defined(__RCSID) && !defined(lint) -__RCSID("$NetBSD: hash.c,v 1.17 2021/08/28 12:21:53 rillig Exp $"); +__RCSID("$NetBSD: hash.c,v 1.18 2021/08/28 17:11:19 rillig Exp $"); #endif /* @@ -128,20 +128,18 @@ _hsearch(hte_t **table, const char *s, b } /* - * Call function f for each name in the hash table. + * Call the action for each name in the hash table. */ void -_forall(hte_t **table, void (*f)(hte_t *)) +symtab_forall(void (*action)(hte_t *)) { int i; hte_t *hte; - - if (table == NULL) - table = htab; + hte_t **table = htab; for (i = 0; i < HSHSIZ2; i++) { for (hte = table[i]; hte != NULL; hte = hte->h_link) - (*f)(hte); + action(hte); } } Index: src/usr.bin/xlint/lint2/main2.c diff -u src/usr.bin/xlint/lint2/main2.c:1.19 src/usr.bin/xlint/lint2/main2.c:1.20 --- src/usr.bin/xlint/lint2/main2.c:1.19 Sun Aug 22 04:43:44 2021 +++ src/usr.bin/xlint/lint2/main2.c Sat Aug 28 17:11:19 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: main2.c,v 1.19 2021/08/22 04:43:44 rillig Exp $ */ +/* $NetBSD: main2.c,v 1.20 2021/08/28 17:11:19 rillig Exp $ */ /* * Copyright (c) 1994, 1995 Jochen Pohl @@ -37,7 +37,7 @@ #include #if defined(__RCSID) && !defined(lint) -__RCSID("$NetBSD: main2.c,v 1.19 2021/08/22 04:43:44 rillig Exp $"); +__RCSID("$NetBSD: main2.c,v 1.20 2021/08/28 17:11:19 rillig Exp $"); #endif #include @@ -174,7 +174,7 @@ main(int argc, char *argv[]) /* write the lint library */ if (Cflag) { - forall(mkstatic); + symtab_forall(mkstatic); outlib(libname); } @@ -182,13 +182,13 @@ main(int argc, char *argv[]) for (i = 0; libs[i] != NULL; i++) readfile(libs[i]); - forall(mkstatic); + symtab_forall(mkstatic); mainused(); /* perform all tests */ /* TODO: sort the names; hashcode order looks chaotic. */ - forall(check_name); + symtab_forall(check_name); exit(0); /* NOTREACHED */
CVS commit: src/usr.bin/xlint/lint2
Module Name:src Committed By: rillig Date: Sat Aug 28 17:11:19 UTC 2021 Modified Files: src/usr.bin/xlint/lint2: emit2.c externs2.h hash.c main2.c Log Message: lint: remove unused parameter from forall No functional change. To generate a diff of this commit: cvs rdiff -u -r1.20 -r1.21 src/usr.bin/xlint/lint2/emit2.c cvs rdiff -u -r1.12 -r1.13 src/usr.bin/xlint/lint2/externs2.h cvs rdiff -u -r1.17 -r1.18 src/usr.bin/xlint/lint2/hash.c cvs rdiff -u -r1.19 -r1.20 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.
CVS commit: src/usr.bin/xlint/lint2
Module Name:src Committed By: rillig Date: Sun Aug 22 13:21:48 UTC 2021 Modified Files: src/usr.bin/xlint/lint2: read.c Log Message: lint: clean up error handling in lint2 These are edge cases that don't happen in practice, therefore reduce the size of the binary. To generate a diff of this commit: cvs rdiff -u -r1.54 -r1.55 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.
CVS commit: src/usr.bin/xlint/lint2
Module Name:src Committed By: rillig Date: Sun Aug 22 13:21:48 UTC 2021 Modified Files: src/usr.bin/xlint/lint2: read.c Log Message: lint: clean up error handling in lint2 These are edge cases that don't happen in practice, therefore reduce the size of the binary. To generate a diff of this commit: cvs rdiff -u -r1.54 -r1.55 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.54 src/usr.bin/xlint/lint2/read.c:1.55 --- src/usr.bin/xlint/lint2/read.c:1.54 Sun Aug 22 13:12:39 2021 +++ src/usr.bin/xlint/lint2/read.c Sun Aug 22 13:21:48 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: read.c,v 1.54 2021/08/22 13:12:39 rillig Exp $ */ +/* $NetBSD: read.c,v 1.55 2021/08/22 13:21:48 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.54 2021/08/22 13:12:39 rillig Exp $"); +__RCSID("$NetBSD: read.c,v 1.55 2021/08/22 13:21:48 rillig Exp $"); #endif #include @@ -393,17 +393,17 @@ decldef(pos_t *posp, const char *cp) switch (c) { case 'd': if (sym.s_def != NODECL) -inperr("nodecl %c", c); +inperr("def"); sym.s_def = DEF; break; case 'e': if (sym.s_def != NODECL) -inperr("nodecl %c", c); +inperr("decl"); sym.s_def = DECL; break; case 'i': if (sym.s_inline) -inperr("inline %c", c); +inperr("inline"); sym.s_inline = true; break; case 'o': @@ -423,12 +423,12 @@ decldef(pos_t *posp, const char *cp) break; case 't': if (sym.s_def != NODECL) -inperr("nodecl %c", c); +inperr("tdef"); sym.s_def = TDEF; break; case 'u': if (used) -inperr("used %c", c); +inperr("used"); used = true; break; case 'v': @@ -894,7 +894,7 @@ gettlen(const char *cp, const char **epp (void)parse_int(); break; default: - inperr("bad value: %c\n", cp[-1]); + inperr("bad value: %c", cp[-1]); } break; default:
CVS commit: src/usr.bin/xlint/lint2
Module Name:src Committed By: rillig Date: Sun Aug 22 12:32:13 UTC 2021 Modified Files: src/usr.bin/xlint/lint2: read.c Log Message: lint: simplify reading of type qualifiers in lint2 The only producer of .ln files is lint1, which always writes the type qualifiers in the order 'c', 'v', therefore there is no need to expect any other order or check for duplicates. There is no ambiguity since the other type modifiers are neither 'c' nor 'v' and the main types are all uppercase letters. No functional change. To generate a diff of this commit: cvs rdiff -u -r1.52 -r1.53 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.52 src/usr.bin/xlint/lint2/read.c:1.53 --- src/usr.bin/xlint/lint2/read.c:1.52 Sun Aug 22 12:25:16 2021 +++ src/usr.bin/xlint/lint2/read.c Sun Aug 22 12:32:13 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: read.c,v 1.52 2021/08/22 12:25:16 rillig Exp $ */ +/* $NetBSD: read.c,v 1.53 2021/08/22 12:32:13 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.52 2021/08/22 12:25:16 rillig Exp $"); +__RCSID("$NetBSD: read.c,v 1.53 2021/08/22 12:32:13 rillig Exp $"); #endif #include @@ -643,12 +643,12 @@ inptype(const char *cp, const char **epp c = *cp++; - while (c == 'c' || c == 'v') { - if (c == 'c') { - tp->t_const = true; - } else { - tp->t_volatile = true; - } + if (c == 'c') { + tp->t_const = true; + c = *cp++; + } + if (c == 'v') { + tp->t_volatile = true; c = *cp++; } @@ -726,26 +726,15 @@ gettlen(const char *cp, const char **epp char c, s; tspec_t t; int narg, i; - bool cm, vm; cp1 = cp; c = *cp++; - cm = vm = false; - - while (c == 'c' || c == 'v') { - if (c == 'c') { - if (cm) -inperr("cm: %c", c); - cm = true; - } else { - if (vm) -inperr("vm: %c", c); - vm = true; - } + if (c == 'c') + c = *cp++; + if (c == 'v') c = *cp++; - } switch (c) { case 's':
CVS commit: src/usr.bin/xlint/lint2
Module Name:src Committed By: rillig Date: Sun Aug 22 12:32:13 UTC 2021 Modified Files: src/usr.bin/xlint/lint2: read.c Log Message: lint: simplify reading of type qualifiers in lint2 The only producer of .ln files is lint1, which always writes the type qualifiers in the order 'c', 'v', therefore there is no need to expect any other order or check for duplicates. There is no ambiguity since the other type modifiers are neither 'c' nor 'v' and the main types are all uppercase letters. No functional change. To generate a diff of this commit: cvs rdiff -u -r1.52 -r1.53 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.
CVS commit: src/usr.bin/xlint/lint2
Module Name:src Committed By: rillig Date: Sun Aug 22 12:25:16 UTC 2021 Modified Files: src/usr.bin/xlint/lint2: read.c Log Message: lint: clean up switch statements in gettlen Since the switch statements are only about tagged and derived types, there is no need to list all integer and floating types. No functional change. To generate a diff of this commit: cvs rdiff -u -r1.51 -r1.52 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.51 src/usr.bin/xlint/lint2/read.c:1.52 --- src/usr.bin/xlint/lint2/read.c:1.51 Sun Aug 22 12:15:37 2021 +++ src/usr.bin/xlint/lint2/read.c Sun Aug 22 12:25:16 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: read.c,v 1.51 2021/08/22 12:15:37 rillig Exp $ */ +/* $NetBSD: read.c,v 1.52 2021/08/22 12:25: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.51 2021/08/22 12:15:37 rillig Exp $"); +__RCSID("$NetBSD: read.c,v 1.52 2021/08/22 12:25:16 rillig Exp $"); #endif #include @@ -708,33 +708,7 @@ inptype(const char *cp, const char **epp break; } break; - case LONG: - case VOID: - case LDOUBLE: - case DOUBLE: - case FLOAT: - case UQUAD: - case QUAD: -#ifdef INT128_SIZE - case UINT128: - case INT128: -#endif - case ULONG: - case UINT: - case INT: - case USHORT: - case SHORT: - case UCHAR: - case SCHAR: - case CHAR: - case BOOL: - case UNSIGN: - case SIGNED: - case NOTSPEC: - case FCOMPLEX: - case DCOMPLEX: - case LCOMPLEX: - case COMPLEX: + default: break; } @@ -884,12 +858,11 @@ gettlen(const char *cp, const char **epp } break; default: - inperr("bad type: %c %c", c, s); + break; } - if (t == NOTSPEC) { - inperr("undefined type: %c %c", c, s); - } + if (t == NOTSPEC) + inperr("bad type: %c %c", c, s); switch (t) { case ARRAY: @@ -918,8 +891,6 @@ gettlen(const char *cp, const char **epp case UNION: switch (*cp++) { case '1': - (void)inpname(cp, ); - break; case '2': (void)inpname(cp, ); break; @@ -937,33 +908,7 @@ gettlen(const char *cp, const char **epp inperr("bad value: %c\n", cp[-1]); } break; - case FLOAT: - case USHORT: - case SHORT: - case UCHAR: - case SCHAR: - case CHAR: - case BOOL: - case UNSIGN: - case SIGNED: - case NOTSPEC: - case INT: - case UINT: - case DOUBLE: - case LDOUBLE: - case VOID: - case ULONG: - case LONG: - case QUAD: - case UQUAD: -#ifdef INT128_SIZE - case INT128: - case UINT128: -#endif - case FCOMPLEX: - case DCOMPLEX: - case LCOMPLEX: - case COMPLEX: + default: break; }
CVS commit: src/usr.bin/xlint/lint2
Module Name:src Committed By: rillig Date: Sun Aug 22 12:25:16 UTC 2021 Modified Files: src/usr.bin/xlint/lint2: read.c Log Message: lint: clean up switch statements in gettlen Since the switch statements are only about tagged and derived types, there is no need to list all integer and floating types. No functional change. To generate a diff of this commit: cvs rdiff -u -r1.51 -r1.52 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.
CVS commit: src/usr.bin/xlint/lint2
Module Name:src Committed By: rillig Date: Sun Aug 22 12:15:38 UTC 2021 Modified Files: src/usr.bin/xlint/lint2: lint2.h read.c Log Message: lint: convert TP from macro to inline function No functional change. To generate a diff of this commit: cvs rdiff -u -r1.14 -r1.15 src/usr.bin/xlint/lint2/lint2.h cvs rdiff -u -r1.50 -r1.51 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/lint2.h diff -u src/usr.bin/xlint/lint2/lint2.h:1.14 src/usr.bin/xlint/lint2/lint2.h:1.15 --- src/usr.bin/xlint/lint2/lint2.h:1.14 Sat Apr 10 18:36:27 2021 +++ src/usr.bin/xlint/lint2/lint2.h Sun Aug 22 12:15:37 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: lint2.h,v 1.14 2021/04/10 18:36:27 rillig Exp $ */ +/* $NetBSD: lint2.h,v 1.15 2021/08/22 12:15:37 rillig Exp $ */ /* * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. @@ -185,7 +185,11 @@ typedef struct hte { struct hte *h_hte; /* pointer to other htes (for renames) */ } hte_t; -/* maps type indices into pointers to type structs */ -#define TP(idx) (tlst[idx]) - #include "externs2.h" + +/* maps type indices into pointers to type structs */ +static inline type_t * +TP(u_short type_id) { + /* force sequence point for newly parsed type_id */ + return tlst[type_id]; +} Index: src/usr.bin/xlint/lint2/read.c diff -u src/usr.bin/xlint/lint2/read.c:1.50 src/usr.bin/xlint/lint2/read.c:1.51 --- src/usr.bin/xlint/lint2/read.c:1.50 Sun Aug 22 11:57:23 2021 +++ src/usr.bin/xlint/lint2/read.c Sun Aug 22 12:15:37 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: read.c,v 1.50 2021/08/22 11:57:23 rillig Exp $ */ +/* $NetBSD: read.c,v 1.51 2021/08/22 12:15: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.50 2021/08/22 11:57:23 rillig Exp $"); +__RCSID("$NetBSD: read.c,v 1.51 2021/08/22 12:15:37 rillig Exp $"); #endif #include @@ -625,7 +625,7 @@ inptype(const char *cp, const char **epp int narg, i; bool osdef = false; size_t tlen; - u_short tidx, sidx; + u_short tidx; int h; /* If we have this type already, return its index. */ @@ -657,12 +657,10 @@ inptype(const char *cp, const char **epp switch (tp->t_tspec) { case ARRAY: tp->t_dim = parse_int(); - sidx = inptype(cp, ); /* force seq. point! (ditto below) */ - tp->t_subt = TP(sidx); + tp->t_subt = TP(inptype(cp, )); break; case PTR: - sidx = inptype(cp, ); - tp->t_subt = TP(sidx); + tp->t_subt = TP(inptype(cp, )); break; case FUNC: c = *cp; @@ -670,20 +668,18 @@ inptype(const char *cp, const char **epp if (!osdef) tp->t_proto = true; narg = parse_int(); - tp->t_args = xcalloc((size_t)(narg + 1), + tp->t_args = xcalloc((size_t)narg + 1, sizeof(*tp->t_args)); for (i = 0; i < narg; i++) { if (i == narg - 1 && *cp == 'E') { tp->t_vararg = true; cp++; } else { - sidx = inptype(cp, ); - tp->t_args[i] = TP(sidx); + tp->t_args[i] = TP(inptype(cp, )); } } } - sidx = inptype(cp, ); - tp->t_subt = TP(sidx); + tp->t_subt = TP(inptype(cp, )); break; case ENUM: tp->t_tspec = INT; @@ -994,7 +990,7 @@ findtype(const char *cp, size_t len, int } /* - * Store a type and its type string so we can later share this type + * Store a type and its type string, so we can later share this type * if we read the same type string from the input file. */ static u_short
CVS commit: src/usr.bin/xlint/lint2
Module Name:src Committed By: rillig Date: Sun Aug 22 12:15:38 UTC 2021 Modified Files: src/usr.bin/xlint/lint2: lint2.h read.c Log Message: lint: convert TP from macro to inline function No functional change. To generate a diff of this commit: cvs rdiff -u -r1.14 -r1.15 src/usr.bin/xlint/lint2/lint2.h cvs rdiff -u -r1.50 -r1.51 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.
CVS commit: src/usr.bin/xlint/lint2
Module Name:src Committed By: rillig Date: Sun Aug 22 11:57:23 UTC 2021 Modified Files: src/usr.bin/xlint/lint2: read.c Log Message: lint: extract parse_tspec from inptype Add error handling for unknown type character, which led to read of uninitialized memory before. No practical change as far as lint2 only ever reads output from lint1, since that is well-formed. To generate a diff of this commit: cvs rdiff -u -r1.49 -r1.50 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.
CVS commit: src/usr.bin/xlint/lint2
Module Name:src Committed By: rillig Date: Sun Aug 22 11:57:23 UTC 2021 Modified Files: src/usr.bin/xlint/lint2: read.c Log Message: lint: extract parse_tspec from inptype Add error handling for unknown type character, which led to read of uninitialized memory before. No practical change as far as lint2 only ever reads output from lint1, since that is well-formed. To generate a diff of this commit: cvs rdiff -u -r1.49 -r1.50 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.49 src/usr.bin/xlint/lint2/read.c:1.50 --- src/usr.bin/xlint/lint2/read.c:1.49 Sun Aug 8 11:56:35 2021 +++ src/usr.bin/xlint/lint2/read.c Sun Aug 22 11:57:23 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: read.c,v 1.49 2021/08/08 11:56:35 rillig Exp $ */ +/* $NetBSD: read.c,v 1.50 2021/08/22 11:57:23 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.49 2021/08/08 11:56:35 rillig Exp $"); +__RCSID("$NetBSD: read.c,v 1.50 2021/08/22 11:57:23 rillig Exp $"); #endif #include @@ -556,13 +556,70 @@ usedsym(pos_t *posp, const char *cp) hte->h_lusym = >u_next; } +static tspec_t +parse_tspec(const char **pp, char c, bool *osdef) +{ + char s; + + switch (c) { + case 's': /* 'signed' or 'struct' or 'float' */ + case 'u': /* 'unsigned' or 'union' */ + case 'l': /* 'long double' */ + case 'e': /* 'enum' */ + s = c; + c = *(*pp)++; + break; + default: + s = '\0'; + break; + } + + switch (c) { + case 'B': + return BOOL; + case 'C': + return s == 's' ? SCHAR : (s == 'u' ? UCHAR : CHAR); + case 'S': + return s == 'u' ? USHORT : SHORT; + case 'I': + return s == 'u' ? UINT : INT; + case 'L': + return s == 'u' ? ULONG : LONG; + case 'Q': + return s == 'u' ? UQUAD : QUAD; +#ifdef INT128_SIZE + case 'J': + return s == 'u' ? UINT128 : INT128; +#endif + case 'D': + return s == 's' ? FLOAT : (s == 'l' ? LDOUBLE : DOUBLE); + case 'V': + return VOID; + case 'P': + return PTR; + case 'A': + return ARRAY; + case 'F': + case 'f': + *osdef = c == 'f'; + return FUNC; + case 'T': + return s == 'e' ? ENUM : (s == 's' ? STRUCT : UNION); + case 'X': + return s == 's' ? FCOMPLEX + : (s == 'l' ? LCOMPLEX : DCOMPLEX); + default: + inperr("tspec '%c'", c); + } +} + /* * Read a type and return the index of this type. */ static u_short inptype(const char *cp, const char **epp) { - char c, s; + char c; const char *ep; type_t *tp; int narg, i; @@ -595,68 +652,7 @@ inptype(const char *cp, const char **epp c = *cp++; } - switch (c) { - case 's': - case 'u': - case 'l': - case 'e': - s = c; - c = *cp++; - break; - default: - s = '\0'; - break; - } - - switch (c) { - case 'B': - tp->t_tspec = BOOL; - break; - case 'C': - tp->t_tspec = s == 's' ? SCHAR : (s == 'u' ? UCHAR : CHAR); - break; - case 'S': - tp->t_tspec = s == 'u' ? USHORT : SHORT; - break; - case 'I': - tp->t_tspec = s == 'u' ? UINT : INT; - break; - case 'L': - tp->t_tspec = s == 'u' ? ULONG : LONG; - break; - case 'Q': - tp->t_tspec = s == 'u' ? UQUAD : QUAD; - break; -#ifdef INT128_SIZE - case 'J': - tp->t_tspec = s == 'u' ? UINT128 : INT128; - break; -#endif - case 'D': - tp->t_tspec = s == 's' ? FLOAT : (s == 'l' ? LDOUBLE : DOUBLE); - break; - case 'V': - tp->t_tspec = VOID; - break; - case 'P': - tp->t_tspec = PTR; - break; - case 'A': - tp->t_tspec = ARRAY; - break; - case 'F': - case 'f': - osdef = c == 'f'; - tp->t_tspec = FUNC; - break; - case 'T': - tp->t_tspec = s == 'e' ? ENUM : (s == 's' ? STRUCT : UNION); - break; - case 'X': - tp->t_tspec = s == 's' ? FCOMPLEX - : (s == 'l' ? LCOMPLEX : DCOMPLEX); - break; - } + tp->t_tspec = parse_tspec(, c, ); switch (tp->t_tspec) { case ARRAY:
CVS commit: src/usr.bin/xlint/lint2
Module Name:src Committed By: rillig Date: Sun Aug 22 04:43:44 UTC 2021 Modified Files: src/usr.bin/xlint/lint2: chk.c externs2.h main2.c Log Message: lint: constify lint2 checking functions No functional change. To generate a diff of this commit: cvs rdiff -u -r1.43 -r1.44 src/usr.bin/xlint/lint2/chk.c cvs rdiff -u -r1.10 -r1.11 src/usr.bin/xlint/lint2/externs2.h cvs rdiff -u -r1.18 -r1.19 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.43 src/usr.bin/xlint/lint2/chk.c:1.44 --- src/usr.bin/xlint/lint2/chk.c:1.43 Sun Aug 8 11:56:35 2021 +++ src/usr.bin/xlint/lint2/chk.c Sun Aug 22 04:43:44 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: chk.c,v 1.43 2021/08/08 11:56:35 rillig Exp $ */ +/* $NetBSD: chk.c,v 1.44 2021/08/22 04:43:44 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.43 2021/08/08 11:56:35 rillig Exp $"); +__RCSID("$NetBSD: chk.c,v 1.44 2021/08/22 04:43:44 rillig Exp $"); #endif #include @@ -48,23 +48,23 @@ __RCSID("$NetBSD: chk.c,v 1.43 2021/08/0 #include "lint2.h" -static void chkund(hte_t *); -static void chkdnu(hte_t *); -static void chkdnud(hte_t *); -static void chkmd(hte_t *); -static void chkvtui(hte_t *, sym_t *, sym_t *); -static void chkvtdi(hte_t *, sym_t *, sym_t *); -static void chkfaui(hte_t *, sym_t *, sym_t *); -static void chkau(hte_t *, int, sym_t *, sym_t *, pos_t *, +static void chkund(const hte_t *); +static void chkdnu(const hte_t *); +static void chkdnud(const hte_t *); +static void chkmd(const hte_t *); +static void chkvtui(const hte_t *, sym_t *, sym_t *); +static void chkvtdi(const hte_t *, sym_t *, sym_t *); +static void chkfaui(const hte_t *, sym_t *, sym_t *); +static void chkau(const hte_t *, int, sym_t *, sym_t *, pos_t *, fcall_t *, fcall_t *, type_t *, type_t *); -static void chkrvu(hte_t *, sym_t *); -static void chkadecl(hte_t *, sym_t *, sym_t *); -static void printflike(hte_t *,fcall_t *, int, const char *, type_t **); -static void scanflike(hte_t *, fcall_t *, int, const char *, type_t **); -static void badfmt(hte_t *, fcall_t *); -static void inconarg(hte_t *, fcall_t *, int); -static void tofewarg(hte_t *, fcall_t *); -static void tomanyarg(hte_t *, fcall_t *); +static void chkrvu(const hte_t *, sym_t *); +static void chkadecl(const hte_t *, sym_t *, sym_t *); +static void printflike(const hte_t *, fcall_t *, int, const char *, type_t **); +static void scanflike(const hte_t *, fcall_t *, int, const char *, type_t **); +static void badfmt(const hte_t *, fcall_t *); +static void inconarg(const hte_t *, fcall_t *, int); +static void tofewarg(const hte_t *, fcall_t *); +static void tomanyarg(const hte_t *, fcall_t *); static bool eqtype(type_t *, type_t *, bool, bool, bool, bool *); static bool eqargs(type_t *, type_t *, bool *); static bool mnoarg(type_t *, bool *); @@ -86,7 +86,7 @@ mainused(void) * Performs all tests for a single name */ void -chkname(hte_t *hte) +chkname(const hte_t *hte) { sym_t *sym, *def, *pdecl, *decl; @@ -131,7 +131,7 @@ chkname(hte_t *hte) * Print a warning if the name has been used, but not defined. */ static void -chkund(hte_t *hte) +chkund(const hte_t *hte) { fcall_t *fcall; usym_t *usym; @@ -152,7 +152,7 @@ chkund(hte_t *hte) * Print a warning if the name has been defined, but never used. */ static void -chkdnu(hte_t *hte) +chkdnu(const hte_t *hte) { sym_t *sym; @@ -173,7 +173,7 @@ chkdnu(hte_t *hte) * or defined. */ static void -chkdnud(hte_t *hte) +chkdnud(const hte_t *hte) { sym_t *sym; @@ -195,7 +195,7 @@ chkdnud(hte_t *hte) * this name. */ static void -chkmd(hte_t *hte) +chkmd(const hte_t *hte) { sym_t *sym, *def1; char *pos1; @@ -234,7 +234,7 @@ chkmd(hte_t *hte) * call as it's done for function arguments. */ static void -chkvtui(hte_t *hte, sym_t *def, sym_t *decl) +chkvtui(const hte_t *hte, sym_t *def, sym_t *decl) { fcall_t *call; char *pos1; @@ -295,7 +295,7 @@ chkvtui(hte_t *hte, sym_t *def, sym_t *d * types of return values are tested. */ static void -chkvtdi(hte_t *hte, sym_t *def, sym_t *decl) +chkvtdi(const hte_t *hte, sym_t *def, sym_t *decl) { sym_t *sym; type_t *tp1, *tp2; @@ -337,7 +337,7 @@ chkvtdi(hte_t *hte, sym_t *def, sym_t *d * of the same function. */ static void -chkfaui(hte_t *hte, sym_t *def, sym_t *decl) +chkfaui(const hte_t *hte, sym_t *def, sym_t *decl) { type_t *tp1, *tp2, **ap1, **ap2; pos_t *pos1p = NULL; @@ -445,7 +445,7 @@ chkfaui(hte_t *hte, sym_t *def, sym_t *d * */ static void -chkau(hte_t *hte, int n, sym_t *def, sym_t *decl, pos_t *pos1p, +chkau(const hte_t *hte, int n, sym_t *def, sym_t *decl, pos_t *pos1p, fcall_t *call1, fcall_t
CVS commit: src/usr.bin/xlint/lint2
Module Name:src Committed By: rillig Date: Sun Aug 22 04:43:44 UTC 2021 Modified Files: src/usr.bin/xlint/lint2: chk.c externs2.h main2.c Log Message: lint: constify lint2 checking functions No functional change. To generate a diff of this commit: cvs rdiff -u -r1.43 -r1.44 src/usr.bin/xlint/lint2/chk.c cvs rdiff -u -r1.10 -r1.11 src/usr.bin/xlint/lint2/externs2.h cvs rdiff -u -r1.18 -r1.19 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.
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.