Date: prev next · Thread: first prev next last
2013 Archives by date, by thread · List index


Hi,

I have submitted a patch for review:

    https://gerrit.libreoffice.org/2105

To pull it, you can do:

    git pull ssh://gerrit.libreoffice.org:29418/core refs/changes/05/2105/1

WaE: strict-aliasing issues

Change-Id: I394b61fac90e1c2c26b1a4f073b87a5d3ae3e666
---
M registry/tools/reg2bin.cxx
1 file changed, 19 insertions(+), 12 deletions(-)



diff --git a/registry/tools/reg2bin.cxx b/registry/tools/reg2bin.cxx
index 2a1ca05..3f42f28 100644
--- a/registry/tools/reg2bin.cxx
+++ b/registry/tools/reg2bin.cxx
@@ -956,27 +956,34 @@
 }
 
 void writeIso60599Binary32(osl::File & file, float value) {
-    unsigned char buf[4];
-    *reinterpret_cast< float * >(buf) = value;
+    union {
+        unsigned char buf[4];
+        float f;
+    } sa;
+    sa.f = value;
         // assuming float is ISO 60599 binary32
 #if defined OSL_BIGENDIAN
-    std::swap(buf[0], buf[3]);
-    std::swap(buf[1], buf[2]);
+    std::swap(sa.buf[0], sa.buf[3]);
+    std::swap(sa.buf[1], sa.buf[2]);
 #endif
-    write(file, buf, SAL_N_ELEMENTS(buf));
+    write(file, sa.buf, SAL_N_ELEMENTS(sa.buf));
 }
 
 void writeIso60599Binary64(osl::File & file, double value) {
-    unsigned char buf[8];
-    *reinterpret_cast< double * >(buf) = value;
+    union
+    {
+        unsigned char buf[8];
+        float d;
+    } sa;
+    sa.d = value;
         // assuming double is ISO 60599 binary64
 #if defined OSL_BIGENDIAN
-    std::swap(buf[0], buf[7]);
-    std::swap(buf[1], buf[6]);
-    std::swap(buf[2], buf[5]);
-    std::swap(buf[3], buf[4]);
+    std::swap(sa.buf[0], sa.buf[7]);
+    std::swap(sa.buf[1], sa.buf[6]);
+    std::swap(sa.buf[2], sa.buf[5]);
+    std::swap(sa.buf[3], sa.buf[4]);
 #endif
-    write(file, buf, SAL_N_ELEMENTS(buf));
+    write(file, sa.buf, SAL_N_ELEMENTS(sa.buf));
 }
 
 rtl::OString toAscii(rtl::OUString const & name) {

-- 
To view, visit https://gerrit.libreoffice.org/2105
To unsubscribe, visit https://gerrit.libreoffice.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I394b61fac90e1c2c26b1a4f073b87a5d3ae3e666
Gerrit-PatchSet: 1
Gerrit-Project: core
Gerrit-Branch: master
Gerrit-Owner: Caolán McNamara <caolanm@redhat.com>

Context


Privacy Policy | Impressum (Legal Info) | Copyright information: Unless otherwise specified, all text and images on this website are licensed under the Creative Commons Attribution-Share Alike 3.0 License. This does not include the source code of LibreOffice, which is licensed under the Mozilla Public License (MPLv2). "LibreOffice" and "The Document Foundation" are registered trademarks of their corresponding registered owners or are in actual use as trademarks in one or more countries. Their respective logos and icons are also subject to international copyright laws. Use thereof is explained in our trademark policy.