From 5f22fd080bb62a9242d1452415f5073bcfd69c49 Mon Sep 17 00:00:00 2001 From: Samuel Fadel Date: Thu, 11 Feb 2016 15:26:22 -0200 Subject: VoronoiSplat: even better buffer overflow checks. --- voronoisplat.cpp | 9 +++++---- 1 file 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 &sites = *m_sites; std::vector 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); -- cgit v1.2.3