[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Chicken-hackers] [PATCH] Fix undefined behaviour of shifting left s
From: |
Christian Kellermann |
Subject: |
Re: [Chicken-hackers] [PATCH] Fix undefined behaviour of shifting left signed values |
Date: |
Thu, 25 Jun 2015 09:37:17 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux) |
Peter Bex <address@hidden> writes:
> Hello all,
>
> I ran another test with the sanitizer, this time using the undefined
> behaviour checks (-fsanitize=undefined). This found a few problems:
>
> - We are using left shifts on signed types. According to the C spec
> this behaviour is undefined (which is completely retarded, IMHO).
> The even more retarded fix is to simply cast to unsigned and back to
> signed whereever this is done. The attached patch does this for
> master and chicken-5.
I have pushed this as newer compilers will get more aggressive than they
already are and try bending the language laws towards their needs.
I hope code will at least fail in a more predictable mode then.
> - We are dividing floating-point numbers by zero, which is apparently
> undefined. However, we do this to obtain NaN and Inf values.
> As far as I can determine, there is no really portable way to do
> this. See also for example this Stack Overflow thread:
> http://stackoverflow.com/questions/1923837/how-to-use-nan-and-inf-in-c
> It looks like INFINITY is defined in C99, and NAN *may* be.
Let's keep that as it is, it looks like it is too much effort for the
gain atm.
Thank you,
Christian
--
May you be peaceful, may you live in safety, may you be free from
suffering, and may you live with ease.