From 81a39408e68c5b5e8bef599d122a0eb727e704af Mon Sep 17 00:00:00 2001 From: Guillaume Horel Date: Tue, 24 Apr 2018 11:22:24 -0400 Subject: fix hash --- pyisda/credit_index.pyx | 12 +++++++----- 1 file 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 = 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(cursor, p.first.length(), 0) - #0 padding if p.first.length() < 8: + p.first.copy(cursor, p.first.length(), 0) + #0 padding memset(cursor + p.first.length(), 0, 8 - p.first.length()) + else: + p.first.copy(cursor, 8, 0) cursor += 8 memcpy(cursor, self.recovery_rates[p.second].get(), curve.fNumItems * sizeof(double)) h ^= Hash64(buf, buf_size) - free(buf) h = Hash64WithSeed(&self.start_date, sizeof(TDate), h) + h = Hash64WithSeed(&self.base_date, sizeof(TDate), h) h = Hash64WithSeed(self._maturities.data(), sizeof(TDate) * self._maturities.size(), h) - h = Hash64WithSeed(self._weights.data(), sizeof(double) * self._weights.size(), h) + h = Hash64WithSeed(self._weights.data(), sizeof(double) * self._weights.size(), h) return h #@cython.initializedcheck(False) -- cgit v1.2.3-70-g09d2