From 06d6fa187e030f036d70426ba3ce679710b50c59 Mon Sep 17 00:00:00 2001 From: Daniel Arndt Date: Mon, 30 Apr 2018 01:11:36 +0200 Subject: [PATCH] Avoid accessing invalid memory in base/utilities_pack_unpack_04 --- tests/base/utilities_pack_unpack_04.cc | 6 ++++-- tests/base/utilities_pack_unpack_04.output | 1 - 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/base/utilities_pack_unpack_04.cc b/tests/base/utilities_pack_unpack_04.cc index 5c9a74f860..3546ec90fa 100644 --- a/tests/base/utilities_pack_unpack_04.cc +++ b/tests/base/utilities_pack_unpack_04.cc @@ -34,8 +34,10 @@ void check (const T (&object)[N]) T unpacked[N]; Utilities::unpack(buffer, unpacked); - deallog << "Buffer size check: " << (buffer.size() == sizeof(T)*N ? "OK" : "Failed") << std::endl; - deallog << "memcmp check: " << (std::memcmp(buffer.data(), &object, buffer.size()) == 0 ? "OK" : "Failed") << std::endl; + const bool equal_sizes = (buffer.size() == sizeof(T)*N); + deallog << "Buffer size check: " << (equal_sizes ? "OK" : "Failed") << std::endl; + if (equal_sizes) + deallog << "memcmp check: " << (std::memcmp(buffer.data(), &object, buffer.size()) == 0 ? "OK" : "Failed") << std::endl; bool equal=true; for (unsigned int i=0; i