From c1e1da8f10b2039c4924e19ba095a7b1723fa850 Mon Sep 17 00:00:00 2001 From: Patrick Georgi Date: Mon, 2 Jan 2017 18:47:50 +0100 Subject: [PATCH] UPSTREAM: util/romcc: avoid shifting more than the variable's width That's undefined behavior in C Change-Id: I671ed8abf02e57a7cc993d1a85354e905f51717d Original-Signed-off-by: Patrick Georgi Original-Found-by: Coverity Scan #1229557 Original-Reviewed-on: https://review.coreboot.org/18014 Original-Tested-by: build bot (Jenkins) Original-Reviewed-by: Martin Roth Signed-off-by: Aaron Durbin Reviewed-on: https://chromium-review.googlesource.com/425983 Reviewed-by: Patrick Georgi --- util/romcc/romcc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/util/romcc/romcc.c b/util/romcc/romcc.c index b08f8e888a..aa41ccf2ce 100644 --- a/util/romcc/romcc.c +++ b/util/romcc/romcc.c @@ -10021,13 +10021,13 @@ static void simplify_copy(struct compile_state *state, struct triple *ins) /* Ensure I am properly sign extended */ if (size_of(state, right->type) < size_of(state, ins->type) && is_signed(right->type)) { - long_t val; + uint64_t val; int shift; shift = SIZEOF_LONG - size_of(state, right->type); val = left; val <<= shift; val >>= shift; - left = val; + left = (ulong_t)val; } mkconst(state, ins, left); break;