Boost logo

Boost Users :

Subject: [Boost-users] [Format] boost 1.48.0, vs2010 runtime check triggered by cast to smaller type in feed_args.hpp
From: david x callaway (dxc_at_[hidden])
Date: 2011-11-23 10:47:25


running the code below triggers a runtime crash due to casting to a smaller type in feed_args.hpp if -RTCc is given. we turn on this runtime check for debug builds as shown in the sample code. so far the only remedy I've found is to turn off runtime checks for the entire module, not a nice solution. microsoft's suggestion, to use a pragma to turn off the check, doesn't work (not your problem I know).

the same issue exists in boost 1.47.0.

thx
dxc

// ----- cut ----

// boost 1.48.0
// visual studio 10.0, service pack 1, windows 7/64

// using this pragma, per microsoft, does not solve the problem
// #pragma runtime_checks( "", off )

#include <string>
#include <boost/format.hpp>

// compile: cl -EHsc -W4 -I /path/to/boost -MDd check.cp
// runs fine with no runtime check, output as expected

// if you include -RTCc, runtime size checks, it goes into the debugger
// compile: cl -EHsc -W4 -RTCc -I /path/to/boost check.cpp
// static_cast triggers runtime error at feed_args.hpp:168

int main()
{
    std::string documenttype("1");
    std::string key(boost::str(boost::format("name[documenttype:%1%]")%documenttype));
    std::cout << key << "\n"; // expected output: name[documenttype:1]
    return 0;
}
// #pragma runtime_checks( "", restore )


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