X-Git-Url: http://git.code-monkey.de/?a=blobdiff_plain;f=src%2Fpds.c;h=88339d0bd907ec2c81e6f3efef75bb055818dd38;hb=HEAD;hp=6f63e1a1f3943d0b3d241fcbe9f1fc21c08bb01d;hpb=49d3c8e83f5b2e25d605155c1554d2a3b77dcda2;p=umurmur.git diff --git a/src/pds.c b/src/pds.c index 6f63e1a..88339d0 100644 --- a/src/pds.c +++ b/src/pds.c @@ -1,5 +1,5 @@ -/* Copyright (C) 2009-2010, Martin Johansson - Copyright (C) 2005-2010, Thorvald Natvig +/* Copyright (C) 2009-2014, Martin Johansson + Copyright (C) 2005-2014, Thorvald Natvig All rights reserved. @@ -32,6 +32,7 @@ #include #include "pds.h" #include "log.h" +#include "memory.h" /* * Data serialization functions below @@ -102,7 +103,7 @@ int Pds_skip(pds_t *pds, int offset) pds->bOk = false; return 0; } - + } static inline uint64_t next(pds_t *pds) @@ -117,9 +118,7 @@ static inline uint64_t next(pds_t *pds) pds_t *Pds_create(uint8_t *buf, int size) { - pds_t *pds = malloc(sizeof(pds_t)); - if (pds == NULL) - Log_fatal("Out of memory"); + pds_t *pds = Memory_safeMalloc(1, sizeof(pds_t)); pds->data = buf; pds->offset = pds->overshoot = 0; pds->maxsize = size; @@ -135,9 +134,9 @@ void Pds_free(pds_t *pds) void Pds_add_double(pds_t *pds, double value) { double64u_t u; - + u.dval = value; - + Pds_add_numval(pds, u.u64); } @@ -150,7 +149,7 @@ double Pds_get_double(pds_t *pds) void Pds_add_numval(pds_t *pds, const uint64_t value) { uint64_t i = value; - + if ((i & 0x8000000000000000LL) && (~i < 0x100000000LL)) { // Signed number. i = ~i; @@ -200,12 +199,12 @@ void Pds_add_numval(pds_t *pds, const uint64_t value) append_val(pds, i & 0xFF); } } - + uint64_t Pds_get_numval(pds_t *pds) { uint64_t i = 0; uint64_t v = next(pds); - + if ((v & 0x80) == 0x00) { i=(v & 0x7F); } else if ((v & 0xC0) == 0x80) {