Skip to content

Use of uninitialized variable in bobyqa altmov_() #36

Closed
@gddl

Description

@gddl

Under some circumstances the variable ibdsav is used uninitialized.
altmov_() in bobyqa.c

997    if (ibdsav < 0) {
998        xnew[-ibdsav] = sl[-ibdsav];
999    }

The following test code shows the situation that causes lots of NANs in altmov_() and leaves the ibdsav uninitialized. I have no idea, how the correct result for this input should look like - at least it shouldn't segfault. Tested on 64 Bit Linux architectures, gcc 4.8.2.

nlopt-test.cc

/* LN_BOBYQA test causing use of unitialized variable (64 Bit architecture only).
 */

#include <nlopt.hpp>
#include <vector>
#include <limits>
#include <xmmintrin.h>
#include <cstdio>

double callback(const std::vector<double>& x, std::vector<double>& grad, void* data)
{
    return 0.0010540095162719094;
}

int main()
{
    _mm_setcsr(_mm_getcsr() | (_MM_FLUSH_ZERO_ON));

    std::vector<double> lowerBounds(2, 0.0);
    std::vector<double> upperBounds(2, 0.0);
    lowerBounds[0] = -3.1415926535897931;
    lowerBounds[1] = -2.2250738585072014e-307;
    upperBounds[0] = 3.1415926535897931;
    upperBounds[1] = 2.4475812443579215e-307;

    nlopt::opt opt(nlopt::LN_BOBYQA, 2);

    opt.set_lower_bounds(lowerBounds);
    opt.set_upper_bounds(upperBounds);

    opt.set_min_objective(callback, 0);
    opt.set_xtol_rel(1.0e-8);

    double minf;
    std::vector<double> x(2, 0.0);
    x[0] = -0.59243378920273182;
    x[1] = -1.9140531208103923e-307;

    opt.optimize(x, minf);

    return 0;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions