Module Name: src Committed By: rillig Date: Tue Mar 11 22:12:35 UTC 2025
Modified Files: src/usr.bin/xlint/lint1: tree.c Log Message: lint: fix saturated multiplication in integer constraints check After the change from ui_max_value to si_max_value in tree.c 1.675 from 2025-02-27, it was wrong to divide the maximum value by 2 once more. To generate a diff of this commit: cvs rdiff -u -r1.675 -r1.676 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/tree.c diff -u src/usr.bin/xlint/lint1/tree.c:1.675 src/usr.bin/xlint/lint1/tree.c:1.676 --- src/usr.bin/xlint/lint1/tree.c:1.675 Thu Feb 27 23:46:30 2025 +++ src/usr.bin/xlint/lint1/tree.c Tue Mar 11 22:12:35 2025 @@ -1,4 +1,4 @@ -/* $NetBSD: tree.c,v 1.675 2025/02/27 23:46:30 rillig Exp $ */ +/* $NetBSD: tree.c,v 1.676 2025/03/11 22:12:35 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.675 2025/02/27 23:46:30 rillig Exp $"); +__RCSID("$NetBSD: tree.c,v 1.676 2025/03/11 22:12:35 rillig Exp $"); #endif #include <float.h> @@ -152,14 +152,14 @@ si_mult_sat(const type_t *tp, int64_t l, uint64_t al = s64_abs(l); uint64_t ar = s64_abs(r); bool neg = (l >= 0) != (r >= 0); - uint64_t max = (uint64_t)si_max_value(tp); - uint64_t max_prod = max + (neg ? 1 : 0); + int64_t max = si_max_value(tp); + uint64_t max_prod = (uint64_t)max + (neg ? 1 : 0); if (al == 0 || ar <= max_prod / al) return l * r; else if (neg) - return -1 - (int64_t)(max >> 1); + return -1 - max; else - return (int64_t)(max >> 1); + return max; } static int64_t