From ca59c95c2627bf7703eefc204623371d2fd0a7d0 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Mon, 15 Jun 2015 17:47:49 +1000 Subject: [PATCH] image: add bounds check for index operators --- image.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/image.cpp b/image.cpp index 6fcfea04..ef034cc0 100644 --- a/image.cpp +++ b/image.cpp @@ -258,6 +258,9 @@ template T buffer::operator[] (point<2,size_t> p) const { + CHECK_LT (p.x, w); + CHECK_LT (p.y, h); + return begin ()[p.y * s + p.x]; } @@ -267,6 +270,9 @@ template T& buffer::operator[] (point<2,size_t> p) { + CHECK_LT (p.x, w); + CHECK_LT (p.y, h); + return begin ()[p.y * s + p.x]; } @@ -276,6 +282,8 @@ template T buffer::operator[] (size_t idx) const { + CHECK_LT (idx, h * s); + return begin ()[idx]; } @@ -285,6 +293,8 @@ template T& buffer::operator[] (size_t idx) { + CHECK_LT (idx, h * s); + return begin ()[idx]; }