Module Name: src Committed By: rillig Date: Sat Jul 2 10:47:29 UTC 2022
Modified Files: src/usr.bin/xlint/lint1: tree.c Log Message: lint: prevent undefined behavior when folding '<<' or '>>' To generate a diff of this commit: cvs rdiff -u -r1.468 -r1.469 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.468 src/usr.bin/xlint/lint1/tree.c:1.469 --- src/usr.bin/xlint/lint1/tree.c:1.468 Sat Jul 2 10:41:13 2022 +++ src/usr.bin/xlint/lint1/tree.c Sat Jul 2 10:47:29 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: tree.c,v 1.468 2022/07/02 10:41:13 rillig Exp $ */ +/* $NetBSD: tree.c,v 1.469 2022/07/02 10:47:29 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.468 2022/07/02 10:41:13 rillig Exp $"); +__RCSID("$NetBSD: tree.c,v 1.469 2022/07/02 10:47:29 rillig Exp $"); #endif #include <float.h> @@ -3507,16 +3507,16 @@ fold(tnode_t *tn) ovfl = true; break; case SHL: - /* TODO: warn against out-of-bounds 'sr'. */ - q = utyp ? (int64_t)(ul << sr) : sl << sr; + /* TODO: warn about out-of-bounds 'sr'. */ + q = utyp ? (int64_t)(ul << (sr & 63)) : sl << (sr & 63); break; case SHR: /* * The sign must be explicitly extended because * shifts of signed values are implementation dependent. */ - /* TODO: warn against out-of-bounds 'sr'. */ - q = ul >> sr; + /* TODO: warn about out-of-bounds 'sr'. */ + q = ul >> (sr & 63); q = convert_integer(q, t, size_in_bits(t) - (int)sr); break; case LT: