diff options
author | Graham Miller <graham.miller@gmail.com> | 2011-02-09 18:49:53 -0500 |
---|---|---|
committer | Graham Miller <graham.miller@gmail.com> | 2011-02-09 18:49:53 -0500 |
commit | 4e228b5d61e25823b573457b170ad012c86a0a71 (patch) | |
tree | 2c5a9da5750b6db4e8dc6dec5c671c8982882482 | |
parent | ab75d98b84db3583ed51042dcf470d4e1b05d413 (diff) | |
download | libgob-4e228b5d61e25823b573457b170ad012c86a0a71.tar.gz libgob-4e228b5d61e25823b573457b170ad012c86a0a71.tar.bz2 |
changed encode_double to use memecpy0.3
-rw-r--r-- | encode.c | 6 | ||||
-rw-r--r-- | encode_test.c | 3 |
2 files changed, 7 insertions, 2 deletions
@@ -80,7 +80,11 @@ int gob_encode_boolean(char *buf, size_t buf_size, int b) { } int gob_encode_double(char *buf, size_t buf_size, double d) { - return gob_encode_unsigned_long_long(buf, buf_size, flip_unsigned_long_long(*(unsigned long long*)&d)); + unsigned long long ull = 0; + memcpy((char*)&ull, &d, sizeof(double)); + unsigned long long rev_ull = flip_unsigned_long_long(ull); + + return gob_encode_unsigned_long_long(buf, buf_size, rev_ull); } int gob_encode_string(char *buf, size_t buf_size, const char *s) { diff --git a/encode_test.c b/encode_test.c index 6b70a81..dea53d7 100644 --- a/encode_test.c +++ b/encode_test.c @@ -74,7 +74,8 @@ void test_flip_unsigned_long_long(){ void test_gob_encode_double() { char buf[1024]; - int num_bytes = gob_encode_double(buf, 1024, 17.0); + double doubleval = 17; + int num_bytes = gob_encode_double(buf, 1024, doubleval); CU_ASSERT_EQUAL(3, num_bytes); CU_ASSERT_EQUAL((char)0xFE, buf[0]); CU_ASSERT_EQUAL((char)0x31, buf[1]); |