summaryrefslogtreecommitdiff
path: root/src/os/object/xdrstream.cc
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2018-12-05 14:41:08 +0100
committerDaniel Friesel <derf@finalrewind.org>2018-12-05 14:41:08 +0100
commit9df610bbcde89aed4fb71f1fa73d9246ee1fe370 (patch)
tree9f1c9762d4fc398cc502d89a5081c0d55f44e0ff /src/os/object/xdrstream.cc
parentbb1c35235b71079b20f469421a895b038bcfa0db (diff)
XDR: Use unions instead of casts for float/double<->int conversion
Diffstat (limited to 'src/os/object/xdrstream.cc')
-rw-r--r--src/os/object/xdrstream.cc14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/os/object/xdrstream.cc b/src/os/object/xdrstream.cc
index 888153b..ad708be 100644
--- a/src/os/object/xdrstream.cc
+++ b/src/os/object/xdrstream.cc
@@ -70,13 +70,23 @@ XDRStream & XDRStream::operator<<(int64_t number)
XDRStream & XDRStream::operator<<(float number)
{
- *this << *(uint32_t*)&number;
+ union {
+ uint32_t i;
+ float f;
+ } v;
+ v.f = number;
+ *this << v.i;
return *this;
}
XDRStream & XDRStream::operator<<(double number)
{
- *this << *(uint64_t*)&number;
+ union {
+ uint64_t i;
+ double d;
+ } v;
+ v.d = number;
+ *this << v.i;
return *this;
}