Boost logo

Boost Users :

From: Paul Giaccone (paulg_at_[hidden])
Date: 2007-04-13 07:59:14


I have a bug in my program that looks as though it might be in the
macros in test.

The following line gives me a segmentation fault:

    BOOST_CHECK_SMALL(var[a][b].first, accuracy);

The variable "var" is of type boost::shared_array<std::pair<double,
std::valarray<double> > >, for which memory has been allocated as
follows (with variable names disguised):

    const unsigned int num_elements1 = /* some value */;
    const unsigned int num_elements2 = /* some other value */;
    const unsigned int num_elements3 = /* another value */;
    boost::shared_array<boost::shared_array<std::pair<double,
std::valarray<double> > > > var_array(
        new boost::shared_array<std::pair<double, std::valarray<double>
> >[num_elements1]);

    for (unsigned int a = 0; a != num_elements1; ++a)
    {
        var[a].reset(new std::pair<double, std::valarray<double>
>[num_elements2]);

        for (b = FirstSolution; b != num_elements2; ++b)
        {
            var[a][b].second.resize(num_elements3);
        }
    }

The variable "accuracy" is of type double.

The variable is then passed to a test case:

    test_suite -> add(BOOST_TEST_CASE(boost::bind(my_test, var)));

with this header:

    void
my_test(boost::shared_array<boost::shared_array<std::pair<double,
std::valarray<double> > > >& var)

Within this test, "var" is passed to another function (by reference) and
its contents are set.

Outputting the contents shows they have been set OK (using the same
array indices, note), but the segmentation fault occurs when the
BOOST_CHECK_SMALL macro is used.

I am using version 1.33.1 of Boost for gcc 3.2.3. I am linking against
-lboost_unit_test_framework-gcc-d-1_33_1 and -lm

I'm sure I have used this before without any problems in Linux. The
program works perfectly well in Windows using MSVC and Boost version 1.33.1.

Are there any other link flags I should be using? Is there something
else I have missed?

Of course, it is entirely possible that I have an array-out-of-bounds
error in my code or something like that, but my diagnostics aren't
picking anything like this up, and the Windows version does not report
any errors with security checks enabled, and, as I say, outputting the
values to std::cout does not cause a segmentation fault.

Is it possible that the BOOST_CHECK_* macros don't work with
std::valarray in Boost 1.33.1 for gcc 3.2.3?

Thanks.


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