aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamuel Fadel <samuelfadel@gmail.com>2016-02-11 15:26:22 -0200
committerSamuel Fadel <samuelfadel@gmail.com>2016-02-11 15:26:22 -0200
commit5f22fd080bb62a9242d1452415f5073bcfd69c49 (patch)
tree373cbc75b194452a0f7f6bb1bd1fb8356cd11d83
parentb78bc59aa5916df41ac61a25fde16bfe7259e75e (diff)
VoronoiSplat: even better buffer overflow checks.
-rw-r--r--voronoisplat.cpp9
1 files changed, 5 insertions, 4 deletions
diff --git a/voronoisplat.cpp b/voronoisplat.cpp
index da81817..ad553ba 100644
--- a/voronoisplat.cpp
+++ b/voronoisplat.cpp
@@ -524,13 +524,14 @@ void VoronoiSplatRenderer::computeDT()
const std::vector<float> &sites = *m_sites;
std::vector<float> buf(w*h);
for (unsigned i = 0; i < sites.size(); i += 2) {
- unsigned bufIndex = unsigned(m_sy(sites[i + 1]))*h + unsigned(m_sx(sites[i]));
- if (bufIndex > buf.size()) {
- // points outside our scale
+ int x = int(m_sx(sites[i]));
+ int y = int(m_sy(sites[i + 1]));
+ if (x < 0 || x >= w || y < 0 || y >= h) {
+ // point out of bounds
continue;
}
- buf[bufIndex] = i/2.0f + 1.0f;
+ buf[x + y*w] = i/2.0f + 1.0f;
}
skelft2DFT(0, buf.data(), 0, 0, w, h, w);