stormslowly / googletest

Automatically exported from code.google.com/p/googletest
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

Avoid calling PrintToString and friends until printing is required #439

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
For background, please see
https://code.google.com/p/chromium/issues/detail?id=64887

It looks like gtest tries to print some values even before they are needed.
For composite types that don't define operator<<, it just prints out the hex 
dump.

Combined, this leads to Valgrind "uninitialized memory used" reports when using 
googletest with structs that have internal gaps (e.g. padding), even if the 
values are not printed.

A possible solution is to only do the hex dump when printing is actually 
required (e.g. assertion failure) to avoid Valgrind reports for most users.
This should probably be done only when running under Valgrind, to increase the 
code coverage by other runs (e.g. ASan). Dynamic annotations [1] provide a 
RunningOnValgrind() function which allows this run-time check.

[1] 
http://src.chromium.org/viewvc/chrome/trunk/src/base/third_party/dynamic_annotat
ions/dynamic_annotations.h?revision=87469

Original issue reported on code.google.com by timurrrr@chromium.org on 26 Jul 2013 at 10:13

GoogleCodeExporter commented 9 years ago

Original comment by timurrrr@chromium.org on 26 Jul 2013 at 10:13

GoogleCodeExporter commented 9 years ago
I replied on the Chromium bug to explain why we intend this behavior.  Let's 
continue the discussion on that bug.

Original comment by w...@google.com on 26 Jul 2013 at 11:03