Boost logo

Boost Users :

Subject: [Boost-users] [format] crash on windows / inquiry
From: Tore Halvorsen (tore.halvorsen_at_[hidden])
Date: 2008-10-17 03:51:53


I just wondering about two things with the format library.


The following program crashes on windows - is this intentional?

#include <boost/format.hpp>

int main(int argc, char* argv[])
    boost::format f("%s %s");
    f.exceptions(boost::io::no_error_bits); // not needed, but just in case

    char const* null_cstr = 0;
    char const* empty_cstr = "";

    f % empty_cstr; // triggers debug assertion failure
    f % null_cstr; // triggers access violation

        return EXIT_SUCCESS;

The debug assertion failure only happens on a debug build, of course.
I can understand the access violation on a null string, but that
feature makes it unsuitable for a sprintf replacement.


Is there a way to determine the number of expected arguments in a
format object?

Looks like the basic_format::num_args_ is exactly what I'm looking
for, but I can't find this exposed anywhere.

Going through a loop and catching exceptions is one way of getting the
number of expected arguments, but it feels wrong.

Eld på åren og sol på eng gjer mannen fegen og fjåg. [Jøtul]
<demo> 2008 Tore Halvorsen || +052 0553034554

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at