[PATCH] fix KJS crash on some more strict platforms

Helge Deller deller at gmx.de
Tue Dec 16 22:27:04 GMT 2003


On Tuesday 16 December 2003 23:13, Shaheed wrote:
> On Tuesday 16 December 2003 21:08, Helge Deller wrote:
> > Some platforms are pretty strict about the alignment for some types
> > of variables.
> >
> > Code like this (taken from kdelibs/kjs/internal.cpp):
> > const unsigned char NaN_Bytes[] = { 0x7f, 0xf8, 0, 0, 0, 0, 0, 0 };
> > ....
> > double x = * (double*) NaN_Bytes;
> 
> Isn't this also broken in an endianness sense? 

Yes and No - in the real code the endianess is taken into account.
Take a look at the patch I attached (or the original source), the 
#ifdef BIGENDIAN... preprocessor switches are there.

> Hmmm. I'm not an expert, but  according to:
> 
> http://research.microsoft.com/~hollasch/cgindex/coding/ieeefloat.html
> 
> I would suggest something like this (not tested):
> 
> const Q_INT64 qNaN = 0x7ff8000000000001LL; // Quiet NaN
> const Q_INT64 sNaN = 0x7ff0000000000001LL; // SignallingNaN

I didn't wanted to recode the code. Of course using Q_INT64 is cleaner,
but I think KJS is generic code which should not be bound to Qt and is
used for Safari too. But I'm no maintainer or expert of this code....

Helge




More information about the kde-core-devel mailing list