Boost logo

Boost Users :

From: Simon Clift (ssclift_at_[hidden])
Date: 2003-08-28 17:40:17


Hi folks,

There appears to be a bug in boost::format, an unitialized value
problem spotted when I was using valgrind on a program of mine.

The following test code illustrates the (admittedly minor?) problem:

#include <boost/format.hpp>
#include <iostream>
using namespace std;

int main()
{
        int dummy = 5;
        cout << boost::format( "%05d" ) % dummy << endl;
        dummy = 0;
        cout << boost::format( "%05d" ) % dummy << endl;
};

I compiled this with -g and when run with valgrind it seems that
the put_last function in feed_args.hpp sends an uninitialized value
into the standard library <<(int) operator when the integer to
be printed is 0 and leading zeros are specified. Valgrind reports
(clipped for size) on the second ::format call (but not the first)
of the test code:

==28879== Conditional jump or move depends on uninitialised value(s)
==28879== at 0x40289470: (within /usr/lib/libstdc++.so.5.0.3)
...
==28879== by 0x4028F36B: std::ostream::operator<<(int) (in
/usr/lib/libstdc++.so.5.0.3)
==28879== by 0x804CF8D: void boost::io::detail::(anonymous
namespace)::put_last<char, std::char_traits<char>,
int>(std::basic_ostream<char, std::char_traits<char> >&, int&)
(feed_args.hpp:114)
==28879== by 0x804C9A2:
_ZN5boost2io6detail31_GLOBAL__N_test00Fill.cppfx7Zjb3putIcSt11char_traitsIcERiEEvT1_RKNS1_11format_itemIT_T0_EERSbIS9_SA_SaIS9_EERSt19basic_ostringstreamIS9_SA_SE_E (feed_args.hpp:176)
==28879== by 0x804BF44: void boost::io::detail::distribute<char,
std::char_traits<char>, int&>(boost::basic_format<char,
std::char_traits<char> >&, int&) (feed_args.hpp:237)
==28879== by 0x804ABB6:
_ZN5boost2io6detail4feedIcSt11char_traitsIcERiEERNS_12basic_formatIT_T0_EESA_T1_ (feed_args.hpp:246)
==28879== by 0x804A14B: boost::basic_format<char,
std::char_traits<char> >& boost::basic_format<char,
std::char_traits<char> >::operator%<int>(int&) (format_class.hpp:69)
...

Hope this helps. Otherwise I'm enjoying using boost!

Best regards
--- Simon

-- 
Simon Clift                  E-mail: ssclift at math dot uwaterloo dot ca
Ph.D. Student
Scientific Computation Group
University of Waterloo
Waterloo, Ontario, Canada
N2L 3G1

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net