]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Avoid accessing invalid memory in base/utilities_pack_unpack_04 6391/head
authorDaniel Arndt <daniel.arndt@iwr.uni-heidelberg.de>
Sun, 29 Apr 2018 23:11:36 +0000 (01:11 +0200)
committerDaniel Arndt <daniel.arndt@iwr.uni-heidelberg.de>
Sun, 29 Apr 2018 23:45:50 +0000 (01:45 +0200)
tests/base/utilities_pack_unpack_04.cc
tests/base/utilities_pack_unpack_04.output

index 5c9a74f86048d0edf8833d2d81580b8f1a2b97f2..3546ec90fa3b4329da1a052d12bd24b9d82f9d5a 100644 (file)
@@ -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<N; ++i)
index a4b19aca522936a56856483d94ff13301525a836..32ca1ae80622a939a59e228ca25fbf4a136dfbd6 100644 (file)
@@ -3,6 +3,5 @@ DEAL::Buffer size check: OK
 DEAL::memcmp check: OK
 DEAL::direct cmp: OK
 DEAL::Buffer size check: Failed
-DEAL::memcmp check: Failed
 DEAL::direct cmp: OK
 DEAL::OK!

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.