[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Chicken-hackers] [PATCH] Fix undefined behaviour of shifting left signe

From: Peter Bex
Subject: [Chicken-hackers] [PATCH] Fix undefined behaviour of shifting left signed values
Date: Sun, 21 Jun 2015 15:42:48 +0200
User-agent: Mutt/1.5.21 (2010-09-15)

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.

- 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:
   It looks like INFINITY is defined in C99, and NAN *may* be.

Fixing the signed shift did not fix the build on Macppc, so effectively
this patch "does nothing" and I wasn't sure I should even be sending
this mail.  However, it might make the code a little more robust if
there are C compilers that abuse this undefined behaviour in strange

Any thoughts on whether we should, and if so, how to, fix the undefined
division by zero behaviour?  In CHICKEN 5, all these uses seem to be in
functions marked OBSOLETE, so that "problem" may go away by itself.


Attachment: 0001-Avoid-shifting-signed-values-which-is-undefined-beha.CHICKEN-5.patch
Description: Text Data

Attachment: 0001-Avoid-shifting-signed-values-which-is-undefined-beha.MASTER.patch
Description: Text Data

Attachment: signature.asc
Description: Digital signature

reply via email to

[Prev in Thread] Current Thread [Next in Thread]