Permalink
Browse files

fix edge case memory corruption during grid encoding with odd size gr…

…id widths - refs mapnik/mapnik#1584
  • Loading branch information...
1 parent 525319a commit 064c9d29616190c97202d90268565230fa313681 Dane Springmeyer committed Nov 22, 2012
Showing with 6 additions and 6 deletions.
  1. +2 −2 src/js_grid_utils.hpp
  2. +2 −2 src/mapnik_grid.cpp
  3. +2 −2 src/mapnik_grid_view.cpp
View
@@ -98,7 +98,7 @@ static void grid2utf(T const& grid_type,
// start counting at utf8 codepoint 32, aka space character
uint16_t codepoint = 32;
- unsigned array_size = static_cast<unsigned int>(grid_type.width()/resolution);
+ unsigned array_size = std::ceil(grid_type.width()/static_cast<float>(resolution));
for (unsigned y = 0; y < grid_type.height(); y=y+resolution)
{
uint16_t idx = 0;
@@ -272,7 +272,7 @@ static void grid2utf(T const& grid_type,
uint16_t codepoint = 32;
uint16_t row_idx = 0;
- unsigned array_size = static_cast<unsigned int>(grid_type.width()/resolution);
+ unsigned array_size = std::ceil(grid_type.width()/static_cast<float>(resolution));
for (unsigned y = 0; y < grid_type.height(); y=y+resolution)
{
uint16_t idx = 0;
View
@@ -376,7 +376,7 @@ Handle<Value> Grid::encodeSync(const Arguments& args) // format, resolution
// Create the return hash.
Local<Object> json = Object::New();
Local<Array> grid_array = Array::New();
- unsigned array_size = static_cast<unsigned int>(grid_type.width()/resolution);
+ unsigned array_size = std::ceil(grid_type.width()/static_cast<float>(resolution));
for (unsigned j=0;j<lines.size();++j)
{
grid_array->Set(j,String::New(&lines[j],array_size));
@@ -532,7 +532,7 @@ void Grid::EIO_AfterEncode(uv_work_t* req)
// Create the return hash.
Local<Object> json = Object::New();
Local<Array> grid_array = Array::New(closure->lines.size());
- unsigned array_size = static_cast<unsigned int>(grid_type.width()/closure->resolution);
+ unsigned array_size = std::ceil(grid_type.width()/static_cast<float>(closure->resolution));
for (unsigned j=0;j<closure->lines.size();++j)
{
grid_array->Set(j,String::New(&closure->lines[j],array_size));
View
@@ -334,7 +334,7 @@ Handle<Value> GridView::encodeSync(const Arguments& args)
// Create the return hash.
Local<Object> json = Object::New();
Local<Array> grid_array = Array::New();
- unsigned array_size = static_cast<unsigned int>(grid_type.width()/resolution);
+ unsigned array_size = std::ceil(grid_type.width()/static_cast<float>(resolution));
for (unsigned j=0;j<lines.size();++j)
{
grid_array->Set(j,String::New(&lines[j],array_size));
@@ -493,7 +493,7 @@ void GridView::EIO_AfterEncode(uv_work_t* req)
// Create the return hash.
Local<Object> json = Object::New();
Local<Array> grid_array = Array::New(closure->lines.size());
- unsigned array_size = static_cast<unsigned int>(grid_type.width()/closure->resolution);
+ unsigned array_size = std::ceil(grid_type.width()/static_cast<float>(closure->resolution));
for (unsigned j=0;j<closure->lines.size();++j)
{
grid_array->Set(j,String::New(&closure->lines[j],array_size));

1 comment on commit 064c9d2

Please sign in to comment.