From cb0d8295bf9f527edc756cbb4f70c45b54151b57 Mon Sep 17 00:00:00 2001 From: Christopher Lackner Date: Wed, 25 Nov 2020 22:07:07 +0100 Subject: [PATCH] fix hashing of bitarray (uninitialized value in HashArchive & random values at end) --- libsrc/core/archive.hpp | 2 +- libsrc/core/bitarray.cpp | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/libsrc/core/archive.hpp b/libsrc/core/archive.hpp index 2a006693..d56e3f7f 100644 --- a/libsrc/core/archive.hpp +++ b/libsrc/core/archive.hpp @@ -916,7 +916,7 @@ namespace ngcore class NGCORE_API HashArchive : public Archive { - size_t hash_value; + size_t hash_value = 0; char* h; int offset = 0; public: diff --git a/libsrc/core/bitarray.cpp b/libsrc/core/bitarray.cpp index 6b1deac5..1ddd3435 100644 --- a/libsrc/core/bitarray.cpp +++ b/libsrc/core/bitarray.cpp @@ -141,7 +141,20 @@ namespace ngcore archive & size; if(archive.Input()) SetSize(size); - archive.Do(data, size/CHAR_BIT+1); + if(archive.GetVersion("netgen") < "v6.2.2009-20") + archive.Do(data, size/CHAR_BIT+1); + else + { + archive.NeedsVersion("netgen", "v6.2.2009-20"); + archive.Do(data, size/CHAR_BIT); + for(size_t i = 0; i < size%CHAR_BIT; i++) + { + size_t index = CHAR_BIT * (size/CHAR_BIT) + i; + bool b = Test(index); + archive & b; + b ? SetBit(index) : Clear(index); + } + } } else {