diff options
| -rw-r--r-- | pyisda/credit_index.pyx | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/pyisda/credit_index.pyx b/pyisda/credit_index.pyx index 44d345e..a809567 100644 --- a/pyisda/credit_index.pyx +++ b/pyisda/credit_index.pyx @@ -271,7 +271,7 @@ cdef class CreditIndex(CurveList): cdef: TCurve* curve = self._curves[0].get() size_t size = TCurve_size(curve.fNumItems) - size_t buf_size = size + sizeof(size_t) + curve.fNumItems * sizeof(double) + 8 + size_t buf_size = size + curve.fNumItems * sizeof(double) + 8 unsigned char* buf = <unsigned char*>malloc(buf_size) unsigned char* cursor unsigned char* start = buf + size @@ -283,18 +283,20 @@ cdef class CreditIndex(CurveList): cursor = start curve = self._curves[p.second].get() serialize(curve, buf) - p.first.copy(<char*>cursor, p.first.length(), 0) - #0 padding if p.first.length() < 8: + p.first.copy(<char*>cursor, p.first.length(), 0) + #0 padding memset(cursor + p.first.length(), 0, 8 - p.first.length()) + else: + p.first.copy(<char*>cursor, 8, 0) cursor += 8 memcpy(cursor, self.recovery_rates[p.second].get(), curve.fNumItems * sizeof(double)) h ^= Hash64(<char*>buf, buf_size) - free(buf) h = Hash64WithSeed(<char*>&self.start_date, sizeof(TDate), h) + h = Hash64WithSeed(<char*>&self.base_date, sizeof(TDate), h) h = Hash64WithSeed(<char*>self._maturities.data(), sizeof(TDate) * self._maturities.size(), h) - h = Hash64WithSeed(<char*>self._weights.data(), sizeof(double) * self._weights.size(), h) + h = Hash64WithSeed(<char*>self._weights.data(), sizeof(double) * self._weights.size(), h) return h #@cython.initializedcheck(False) |
