Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/xlint/lint1 lint: fix lint warnings



details:   https://anonhg.NetBSD.org/src/rev/3a17f7e5eb99
branches:  trunk
changeset: 1023388:3a17f7e5eb99
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Sep 05 16:03:55 2021 +0000

description:
lint: fix lint warnings

diffstat:

 usr.bin/xlint/lint1/decl.c |  11 +++----
 usr.bin/xlint/lint1/lex.c  |  15 +++++------
 usr.bin/xlint/lint1/tree.c |  59 ++++++++++++++++++++++++---------------------
 3 files changed, 43 insertions(+), 42 deletions(-)

diffs (246 lines):

diff -r 7c519252e8db -r 3a17f7e5eb99 usr.bin/xlint/lint1/decl.c
--- a/usr.bin/xlint/lint1/decl.c        Sun Sep 05 15:15:58 2021 +0000
+++ b/usr.bin/xlint/lint1/decl.c        Sun Sep 05 16:03:55 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: decl.c,v 1.233 2021/09/04 13:45:37 rillig Exp $ */
+/* $NetBSD: decl.c,v 1.234 2021/09/05 16:03:55 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -38,7 +38,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: decl.c,v 1.233 2021/09/04 13:45:37 rillig Exp $");
+__RCSID("$NetBSD: decl.c,v 1.234 2021/09/05 16:03:55 rillig Exp $");
 #endif
 
 #include <sys/param.h>
@@ -907,8 +907,7 @@
                /* FALLTHROUGH */
        default:
                elsz = size_in_bits(tp->t_tspec);
-               if (elsz <= 0)
-                       INTERNAL_ERROR("length(%d)", elsz);
+               lint_assert(elsz > 0);
                break;
        }
        return (int)(elem * elsz);
@@ -917,8 +916,8 @@
 unsigned int
 alignment_in_bits(const type_t *tp)
 {
-       size_t  a;
-       tspec_t t;
+       unsigned int a;
+       tspec_t t;
 
        while (tp->t_tspec == ARRAY)
                tp = tp->t_subt;
diff -r 7c519252e8db -r 3a17f7e5eb99 usr.bin/xlint/lint1/lex.c
--- a/usr.bin/xlint/lint1/lex.c Sun Sep 05 15:15:58 2021 +0000
+++ b/usr.bin/xlint/lint1/lex.c Sun Sep 05 16:03:55 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lex.c,v 1.80 2021/08/29 09:29:32 rillig Exp $ */
+/* $NetBSD: lex.c,v 1.81 2021/09/05 16:03:55 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -38,7 +38,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: lex.c,v 1.80 2021/08/29 09:29:32 rillig Exp $");
+__RCSID("$NetBSD: lex.c,v 1.81 2021/09/05 16:03:55 rillig Exp $");
 #endif
 
 #include <ctype.h>
@@ -555,7 +555,7 @@
 
        errno = 0;
 
-       uq = strtoull(cp, &eptr, base);
+       uq = (uint64_t)strtoull(cp, &eptr, base);
        lint_assert(eptr == cp + len);
        if (errno != 0) {
                /* integer constant out of range */
@@ -679,7 +679,7 @@
 lex_floating_constant(const char *yytext, size_t yyleng)
 {
        const   char *cp;
-       int     len;
+       size_t  len;
        tspec_t typ;
        char    c, *eptr;
        double  d;
@@ -688,10 +688,9 @@
        cp = yytext;
        len = yyleng;
 
-       if (cp[len - 1] == 'i') {
-               /* imaginary, do nothing for now */
-               len--;
-       }
+       if (cp[len - 1] == 'i')
+               len--;          /* imaginary, do nothing for now */
+
        if ((c = cp[len - 1]) == 'f' || c == 'F') {
                typ = FLOAT;
                len--;
diff -r 7c519252e8db -r 3a17f7e5eb99 usr.bin/xlint/lint1/tree.c
--- a/usr.bin/xlint/lint1/tree.c        Sun Sep 05 15:15:58 2021 +0000
+++ b/usr.bin/xlint/lint1/tree.c        Sun Sep 05 16:03:55 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tree.c,v 1.377 2021/09/04 12:30:46 rillig Exp $        */
+/*     $NetBSD: tree.c,v 1.378 2021/09/05 16:03:55 rillig Exp $        */
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: tree.c,v 1.377 2021/09/04 12:30:46 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.378 2021/09/05 16:03:55 rillig Exp $");
 #endif
 
 #include <float.h>
@@ -311,7 +311,7 @@
        tp = expr_zalloc(sizeof(*tp));
        tp->t_tspec = ARRAY;
        tp->t_subt = gettyp(strg->st_tspec);
-       tp->t_dim = len + 1;
+       tp->t_dim = (int)(len + 1);
 
        n->tn_op = STRING;
        n->tn_type = tp;
@@ -1426,8 +1426,7 @@
 }
 
 static void
-check_unconst_function(const type_t *lstp,
-                      const tnode_t *rn, const type_t *rstp)
+check_unconst_function(const type_t *lstp, const tnode_t *rn)
 {
        const char *function_name;
 
@@ -1512,7 +1511,7 @@
        }
 
        if (!tflag)
-               check_unconst_function(lstp, rn, rstp);
+               check_unconst_function(lstp, rn);
 
        return true;
 }
@@ -2290,7 +2289,8 @@
                /* Got already an error because of float --> ptr */
        case LDOUBLE:
        case LCOMPLEX:
-               max = LDBL_MAX;         min = -LDBL_MAX;        break;
+               /* LINTED 248 */
+               max = LDBL_MAX;         min = -max;             break;
        default:
                lint_assert(/*CONSTCOND*/false);
        }
@@ -2363,7 +2363,7 @@
                                    const type_t *tp, op_t op)
 {
        if (nsz > osz &&
-           (nv->v_quad & bit(osz - 1)) != 0 &&
+           (nv->v_quad & bit((unsigned int)(osz - 1))) != 0 &&
            (nv->v_quad & xmask) != xmask) {
                /* extra bits set to 0 in conversion of '%s' to '%s', ... */
                warning(309, type_name(gettyp(ot)),
@@ -2470,8 +2470,8 @@
 convert_constant_check_range(tspec_t ot, const type_t *tp, tspec_t nt,
                             op_t op, int arg, const val_t *v, val_t *nv)
 {
-       int     osz, nsz;
-       int64_t xmask, xmsk1;
+       unsigned int osz, nsz;
+       uint64_t xmask, xmsk1;
 
        osz = size_in_bits(ot);
        nsz = tp->t_bitfield ? tp->t_flen : size_in_bits(nt);
@@ -2511,9 +2511,9 @@
 void
 convert_constant(op_t op, int arg, const type_t *tp, val_t *nv, val_t *v)
 {
-       tspec_t ot, nt;
-       int     sz;
-       bool    range_check;
+       tspec_t ot, nt;
+       unsigned int sz;
+       bool range_check;
 
        /*
         * TODO: make 'v' const; the name of this function does not suggest
@@ -3123,7 +3123,7 @@
                if (sr == 0) {
                        /* division by 0 */
                        error(139);
-                       q = utyp ? UQUAD_MAX : QUAD_MAX;
+                       q = utyp ? -1 : INT64_MAX;
                } else {
                        q = utyp ? (int64_t)(ul / ur) : sl / sr;
                }
@@ -3249,6 +3249,20 @@
        return build_constant(tn->tn_type, v);
 }
 
+static ldbl_t
+floating_error_value(tspec_t t, ldbl_t lv)
+{
+       if (t == FLOAT) {
+               return lv < 0 ? -FLT_MAX : FLT_MAX;
+       } else if (t == DOUBLE) {
+               return lv < 0 ? -DBL_MAX : DBL_MAX;
+       } else {
+               /* LINTED 248: floating-point constant out of range */
+               ldbl_t max = LDBL_MAX;
+               return lv < 0 ? -max : max;
+       }
+}
+
 /*
  * Fold constant nodes having operands with floating point type.
  */
@@ -3285,13 +3299,7 @@
                if (rv == 0.0) {
                        /* division by 0 */
                        error(139);
-                       if (t == FLOAT) {
-                               v->v_ldbl = lv < 0 ? -FLT_MAX : FLT_MAX;
-                       } else if (t == DOUBLE) {
-                               v->v_ldbl = lv < 0 ? -DBL_MAX : DBL_MAX;
-                       } else {
-                               v->v_ldbl = lv < 0 ? -LDBL_MAX : LDBL_MAX;
-                       }
+                       v->v_ldbl = floating_error_value(t, lv);
                } else {
                        v->v_ldbl = lv / rv;
                }
@@ -3332,13 +3340,7 @@
             (v->v_ldbl > DBL_MAX || v->v_ldbl < -DBL_MAX))) {
                /* floating point overflow detected, op %s */
                warning(142, op_name(tn->tn_op));
-               if (t == FLOAT) {
-                       v->v_ldbl = v->v_ldbl < 0 ? -FLT_MAX : FLT_MAX;
-               } else if (t == DOUBLE) {
-                       v->v_ldbl = v->v_ldbl < 0 ? -DBL_MAX : DBL_MAX;
-               } else {
-                       v->v_ldbl = v->v_ldbl < 0 ? -LDBL_MAX : LDBL_MAX;
-               }
+               v->v_ldbl = floating_error_value(t, v->v_ldbl);
                fpe = 0;
        }
 
@@ -3361,6 +3363,7 @@
 /*
  * Create a constant node for offsetof.
  */
+/* ARGSUSED */ /* See implementation comments. */
 tnode_t *
 build_offsetof(const type_t *tp, const sym_t *sym)
 {



Home | Main Index | Thread Index | Old Index