[PATCH] Fix undefined behaviour in lround,llround.

Dave Korn dave.korn.cygwin@gmail.com
Thu Jul 22 21:11:00 GMT 2010

On 19/07/2010 11:37, Corinna Vinschen wrote:
> On Jul 17 18:16, Dave Korn wrote:

>>   Same changelog as before.  OK now/with/without above-mentioned minor
>> alterations?
> The reason not to use `unsigned long long tmp' sounds good to me.
> Keeping the SAFE_LEFT_SHIFT in the header doesn't hurt and might come in
> handy at one point.  So, yes, that looks ok to apply, Dave, especially
> with the annotations (which should be mentioned in the ChangeLog).

  Thanks, applied with the following ChangeLog entry:


	* libm/common/fdlibm.h (SAFE_LEFT_SHIFT): New macro definition.
	(SAFE_RIGHT_SHIFT): Likewise.
	* libm/common/s_llround.c (llround): Annotate shift operations with
	possible shift amount ranges, and use SAFE_RIGHT_SHIFT to avoid
	undefined behaviour.
	* libm/common/s_lround.c (lround): Likewise.


More information about the Newlib mailing list