Module Name:    src
Committed By:   rillig
Date:           Sun Sep  5 16:03:55 UTC 2021

Modified Files:
        src/usr.bin/xlint/lint1: decl.c lex.c tree.c

Log Message:
lint: fix lint warnings


To generate a diff of this commit:
cvs rdiff -u -r1.233 -r1.234 src/usr.bin/xlint/lint1/decl.c
cvs rdiff -u -r1.80 -r1.81 src/usr.bin/xlint/lint1/lex.c
cvs rdiff -u -r1.377 -r1.378 src/usr.bin/xlint/lint1/tree.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/lint1/decl.c
diff -u src/usr.bin/xlint/lint1/decl.c:1.233 src/usr.bin/xlint/lint1/decl.c:1.234
--- src/usr.bin/xlint/lint1/decl.c:1.233	Sat Sep  4 13:45:37 2021
+++ src/usr.bin/xlint/lint1/decl.c	Sun Sep  5 16:03:55 2021
@@ -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 @@ length(const type_t *tp, const char *nam
 		/* 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 @@ length(const type_t *tp, const char *nam
 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;

Index: src/usr.bin/xlint/lint1/lex.c
diff -u src/usr.bin/xlint/lint1/lex.c:1.80 src/usr.bin/xlint/lint1/lex.c:1.81
--- src/usr.bin/xlint/lint1/lex.c:1.80	Sun Aug 29 09:29:32 2021
+++ src/usr.bin/xlint/lint1/lex.c	Sun Sep  5 16:03:55 2021
@@ -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 @@ lex_integer_constant(const char *yytext,
 
 	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 @@ int
 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 @@ lex_floating_constant(const char *yytext
 	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--;

Index: src/usr.bin/xlint/lint1/tree.c
diff -u src/usr.bin/xlint/lint1/tree.c:1.377 src/usr.bin/xlint/lint1/tree.c:1.378
--- src/usr.bin/xlint/lint1/tree.c:1.377	Sat Sep  4 12:30:46 2021
+++ src/usr.bin/xlint/lint1/tree.c	Sun Sep  5 16:03:55 2021
@@ -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 @@ build_string(strg_t *strg)
 	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 @@ is_first_arg_const(const tnode_t *tn)
 }
 
 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 @@ check_assign_void_pointer_compat(op_t op
 	}
 
 	if (!tflag)
-		check_unconst_function(lstp, rn, rstp);
+		check_unconst_function(lstp, rn);
 
 	return true;
 }
@@ -2290,7 +2289,8 @@ convert_constant_floating(op_t op, int a
 		/* 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 @@ convert_constant_check_range_bitand(size
 				    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 @@ static void
 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 @@ convert_constant_check_range(tspec_t ot,
 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 @@ fold(tnode_t *tn)
 		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 @@ fold_test(tnode_t *tn)
 	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 @@ fold_float(tnode_t *tn)
 		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 @@ fold_float(tnode_t *tn)
 	     (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 @@ build_sizeof(const type_t *tp)
 /*
  * Create a constant node for offsetof.
  */
+/* ARGSUSED */ /* See implementation comments. */
 tnode_t *
 build_offsetof(const type_t *tp, const sym_t *sym)
 {

Reply via email to