|
Boost : |
From: Vladimir Prus (ghost_at_[hidden])
Date: 2003-01-28 07:07:16
I've just teached Boost.Build V2 to run unit tests under valgrind --- an
utility for detecting various memory-related errors. I get this error on
some code which uses Boost.Test:
==14051== Conditional jump or move depends on uninitialised value(s)
==14051== at 0x4027211F: (within /usr/lib/libstdc++-3-libc6.2-2-2.10.0.so)
==14051== by 0x80573DA: ???
(/usr/lib/gcc-lib/i386-linux/2.95.4/../../../../include/g++-3/std/bastring.h:220)
==14051== by 0x8055C32: ???
(/usr/lib/gcc-lib/i386-linux/2.95.4/../../../../include/g++-3/std/bastring.h:178)
==14051== by 0x807DCC2:
boost::unit_test_framework::test_case::test_case(char const *, unsigned long,
bool) (/home/ghost/Work/boost/libs/test/src/unit_test_suite.cpp:35)
==14051== by 0x807D911: ???
(/home/ghost/Work/boost/boost/test/unit_test_suite.hpp:114)
==14051== by 0x807D7A1: ???
(/home/ghost/Work/boost/boost/test/unit_test_suite.hpp:265)
==14051== by 0x807D585: main
(/home/ghost/Work/boost/libs/test/src/test_main.cpp:71)
==14051== by 0x402D69F1: __libc_start_main (in /lib/libc-2.3.1.so)
The problems is caused by calling "data()" on std::string, which does not
zero-terminate the returned value, AFAICT. The following patch eliminates
the warning:
--- unit_test_suite.cpp.~1.6.~ Mon Dec 16 09:46:41 2002
+++ unit_test_suite.cpp Tue Jan 28 15:01:41 2003
@@ -228,7 +228,7 @@
if( name_[0] == '&' )
name_.erase( 0, 1 );
- return name_.data();
+ return name_.c_str();
}
} // namespace detail
- Volodya
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk