Index | Thread | Search

From:
Theo Buehler <tb@theobuehler.org>
Subject:
Re: ksh signed overflow
To:
Ted Unangst <tedu@tedunangst.com>
Cc:
tech@openbsd.org
Date:
Tue, 24 Jun 2025 12:17:19 +0200

Download raw body.

Thread
>  		case O_LSHIFT:
>  		case O_LSHIFTASN:
> -			res = vl->val.i << vr->val.i;
> +			{
> +				uint64_t amt = vr->val.u;
> +				if (amt > 64)
> +					amt = 64;
> +				res = vl->val.i << amt;

Leaving aside the fundamental question on type punning, I don't think
this is right. "If the value of the right operand is ... greater than or
equal to the width of the promoted left operand, the behavior is
undefined". So I think you can shift at most by 63 bits.