lint: fix excessive overflow warning after division by zero
This commit is contained in:
parent
76021c6ba1
commit
3e856647d2
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: expr_fold.c,v 1.11 2024/01/06 15:05:24 rillig Exp $ */
|
||||
/* $NetBSD: expr_fold.c,v 1.12 2024/03/09 23:55:11 rillig Exp $ */
|
||||
# 3 "expr_fold.c"
|
||||
|
||||
/*
|
||||
|
@ -114,9 +114,7 @@ fold_mult(void)
|
|||
void
|
||||
fold_div(void)
|
||||
{
|
||||
/* expect+3: error: division by 0 [139] */
|
||||
/* XXX: The following message is redundant. */
|
||||
/* expect+1: warning: operator '/' produces integer overflow [141] */
|
||||
/* expect+1: error: division by 0 [139] */
|
||||
take_int(0 / 0);
|
||||
|
||||
/* expect+1: warning: conversion of 'long' to 'int' is out of range, arg #1 [295] */
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: tree.c,v 1.613 2024/03/09 14:54:14 rillig Exp $ */
|
||||
/* $NetBSD: tree.c,v 1.614 2024/03/09 23:55:11 rillig Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1994, 1995 Jochen Pohl
|
||||
|
@ -37,7 +37,7 @@
|
|||
|
||||
#include <sys/cdefs.h>
|
||||
#if defined(__RCSID)
|
||||
__RCSID("$NetBSD: tree.c,v 1.613 2024/03/09 14:54:14 rillig Exp $");
|
||||
__RCSID("$NetBSD: tree.c,v 1.614 2024/03/09 23:55:11 rillig Exp $");
|
||||
#endif
|
||||
|
||||
#include <float.h>
|
||||
|
@ -809,6 +809,8 @@ fold_constant_integer(tnode_t *tn)
|
|||
ur = sr = tn->u.ops.right->u.value.u.integer;
|
||||
|
||||
uint64_t mask = value_bits(size_in_bits(t));
|
||||
int64_t max_value = (int64_t)(mask >> 1);
|
||||
int64_t min_value = -max_value - 1;
|
||||
bool ovfl = false;
|
||||
|
||||
int64_t si;
|
||||
|
@ -841,11 +843,9 @@ fold_constant_integer(tnode_t *tn)
|
|||
if (sr == 0) {
|
||||
/* division by 0 */
|
||||
error(139);
|
||||
si = utyp ? -1 : INT64_MAX;
|
||||
} else if (!utyp
|
||||
&& (sl & mask) == (mask ^ (mask >> 1)) && sr == -1) {
|
||||
/* operator '%s' produces integer overflow */
|
||||
warning(141, op_name(DIV));
|
||||
si = utyp ? -1 : max_value;
|
||||
} else if (!utyp && sl == min_value && sr == -1) {
|
||||
ovfl = true;
|
||||
si = sl;
|
||||
} else
|
||||
si = utyp ? (int64_t)(ul / ur) : sl / sr;
|
||||
|
|
Loading…
Reference in New Issue