|
Boost Users : |
Subject: [Boost-users] [polygon] Valgrind errors when normalizing any angle polygons
From: Josh Pieper (jpieper_at_[hidden])
Date: 2010-11-04 18:54:12
Hello,
We have been using the 1.44.0 release of polygon for some internal
projects and have come across a number of oddities. The first one
I've got is a valgrind error when normalizing polygons with
numerically large coordinate values. Using the gmp_override.hpp
header does resolve these problems, but my understanding is that it is
the intent for the library to merely be numerically imprecise, rather
than crash, for coordinates which are too large.
Our simplified test case is below, and was compiled on an AMD64 Ubuntu
10.4 system. The first call to Normalize has no problems, but the
second call causes valgrind to report both uninitialized memory usage
and invalid reads. (I can produce the valgrind log on demand, but it
is somewhat large for inclusion in an email). While we have deployed
1.44.0 internally, I tested against the most recent svn version and
the problem still exists.
Is this merely a mis-use of the API?
Regards,
Josh Pieper
------------------------
#include <stdint.h>
#include "boost_polygon/r66294/polygon/polygon.hpp"
typedef boost::polygon::point_data<int32_t> BoostPoint;
typedef boost::polygon::polygon_data<int32_t> BoostPolygon;
typedef boost::polygon::polygon_set_data<int32_t> BoostPolygonSet;
typedef boost::polygon::polygon_with_holes_data<int32_t> BoostPolygonWithHoles;
typedef std::vector<BoostPolygonWithHoles> BoostPolygonWithHolesVector;
template <typename Array>
void Normalize(const Array& data, int32_t scale) {
std::vector<BoostPoint> points;
for (size_t i = 0; i < sizeof(data) / sizeof(*data); i += 2) {
points.push_back(BoostPoint(data[i] / scale, data[i + 1] / scale));
}
using namespace boost::polygon::operators;
BoostPolygonSet poly_set;
poly_set |= BoostPolygon(points.begin(), points.end());
BoostPolygonWithHolesVector normal;
poly_set.get(normal);
}
int main() {
int32_t data[] = {
0, 0,
-1000000, -1000000,
19000000, -1000000,
18292893, 707106,
8292893, -9292893,
8170784, -9440890,
8078584, -9610754,
8000000, -10000000,
8078584, -10389245,
8170784, -10559109,
8292893, -10707106,
18292893, -20707106,
19000000, -19000000,
-1000000, -19000000,
0, -20000000,
0, 0,
};
Normalize(data, 10); // Fine.
Normalize(data, 1); // Crashes.
}
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