Boost logo

Boost Users :

Subject: [Boost-users] [graph] kamada_kawai_spring_layout warnings
From: Michael Olea (oleaj_at_[hidden])
Date: 2014-06-21 14:41:05


Hi.

I'm getting compiler warnings for subscripts out of range from kamada_kawai_spring_layout.hpp.

I'm using boost_55_0, compiled with clang:

Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn)
Target: x86_64-apple-darwin13.2.0
Thread model: posix

../../../../../include/boost/graph/kamada_kawai_spring_layout.hpp:110:49:
warning: array index 2 is past the end of the array (which contains 2 elements) [-Warray-bounds]
        double denom = mat[0][0] * (mat[1][1] * mat[2][2] - mat[2][1] * mat[1][2])

The offending code is:

    template <>
    struct linear_solver<3> {
      template <typename Vec>
      static Vec solve(double mat[2][2], Vec rhs) {
        double denom = mat[0][0] * (mat[1][1] * mat[2][2] - mat[2][1] * mat[1][2])
                     - mat[1][0] * (mat[0][1] * mat[2][2] - mat[2][1] * mat[0][2])
                     + mat[2][0] * (mat[0][1] * mat[1][2] - mat[1][1] * mat[0][2]);
        double x_num = rhs[0] * (mat[1][1] * mat[2][2] - mat[2][1] * mat[1][2])
                     - rhs[1] * (mat[0][1] * mat[2][2] - mat[2][1] * mat[0][2])
                     + rhs[2] * (mat[0][1] * mat[1][2] - mat[1][1] * mat[0][2]);
        double y_num = mat[0][0] * (rhs[1] * mat[2][2] - rhs[2] * mat[1][2])
                     - mat[1][0] * (rhs[0] * mat[2][2] - rhs[2] * mat[0][2])
                     + mat[2][0] * (rhs[0] * mat[1][2] - rhs[1] * mat[0][2]);
        double z_num = mat[0][0] * (mat[1][1] * rhs[2] - mat[2][1] * rhs[1] )
                     - mat[1][0] * (mat[0][1] * rhs[2] - mat[2][1] * rhs[0] )
                     + mat[2][0] * (mat[0][1] * rhs[1] - mat[1][1] * rhs[0] );
        Vec result;
        result[0] = x_num / denom;
        result[1] = y_num / denom;
        result[2] = z_num / denom;
        return result;
      }
    };

Looks like it should be:

static Vec solve(double mat[3][3], Vec rhs) ...

No?



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