[PATCH] fix KJS crash on some more strict platforms

Helge Deller deller at gmx.de
Wed Dec 17 21:37:32 GMT 2003


On Wednesday 17 December 2003 11:32, Harri Porten wrote:
> I'm fine with any of the proposed (and proven to work;) solutions. Apart
> from the STL functions.

First of all thanks for all the feedback I got regarding my last patch here 
on the list ! I tried to find the cleanest solution and attached is now a shiny 
new patch proposal.
It's clean, compiler- and platform independent (it uses an union) and 
was tested by me on i686/SuSE9 & HP-PARISC/Debian.

It would be nice if someone gives his ok on this one.

Helge
-------------- next part --------------
? internal1.xx
Index: internal.cpp
===================================================================
RCS file: /home/kde/kdelibs/kjs/internal.cpp,v
retrieving revision 1.170
diff -u -p -r1.170 internal.cpp
--- internal.cpp	17 Nov 2003 00:48:40 -0000	1.170
+++ internal.cpp	17 Dec 2003 21:21:42 -0000
@@ -55,19 +55,23 @@ extern int kjsyyparse();
 using namespace KJS;
 
 namespace KJS {
+  /* work around some strict alignment requirements 
+     for double variables on some architectures (e.g. PA-RISC) */
+  typedef union { unsigned char b[8]; double d; } kjs_double_t;
+
 #ifdef WORDS_BIGENDIAN
-  const unsigned char NaN_Bytes[] = { 0x7f, 0xf8, 0, 0, 0, 0, 0, 0 };
-  const unsigned char Inf_Bytes[] = { 0x7f, 0xf0, 0, 0, 0, 0, 0, 0 };
+  static const kjs_double_t NaN_Bytes = { { 0x7f, 0xf8, 0, 0, 0, 0, 0, 0 } };
+  static const kjs_double_t Inf_Bytes = { { 0x7f, 0xf0, 0, 0, 0, 0, 0, 0 } };
 #elif defined(arm)
-  const unsigned char NaN_Bytes[] = { 0, 0, 0xf8, 0x7f, 0, 0, 0, 0 };
-  const unsigned char Inf_Bytes[] = { 0, 0, 0xf0, 0x7f, 0, 0, 0, 0 };
+  static const kjs_double_t NaN_Bytes = { { 0, 0, 0xf8, 0x7f, 0, 0, 0, 0 } };
+  static const kjs_double_t Inf_Bytes = { { 0, 0, 0xf0, 0x7f, 0, 0, 0, 0 } };
 #else
-  const unsigned char NaN_Bytes[] = { 0, 0, 0, 0, 0, 0, 0xf8, 0x7f };
-  const unsigned char Inf_Bytes[] = { 0, 0, 0, 0, 0, 0, 0xf0, 0x7f };
+  static const kjs_double_t NaN_Bytes = { { 0, 0, 0, 0, 0, 0, 0xf8, 0x7f } };
+  static const kjs_double_t Inf_Bytes = { { 0, 0, 0, 0, 0, 0, 0xf0, 0x7f } };
 #endif
 
-  const double NaN = *(const double*) NaN_Bytes;
-  const double Inf = *(const double*) Inf_Bytes;
+  const double NaN = NaN_Bytes.d;
+  const double Inf = Inf_Bytes.d;
 }
 
 #ifdef KJS_THREADSUPPORT


More information about the kde-core-devel mailing list