[gegl/soc-2013-n-point-deformation: 14/28] operations: npd: add proper boundary check for get/set pixel functions



commit 653ca8af27cf0aa081ef6e4ca2b899b63c801010
Author: Marek Dvoroznak <dvoromar gmail com>
Date:   Thu Aug 15 01:14:36 2013 +0200

    operations: npd: add proper boundary check for get/set pixel functions

 operations/external/npd.c |   16 ++++++++--------
 1 files changed, 8 insertions(+), 8 deletions(-)
---
diff --git a/operations/external/npd.c b/operations/external/npd.c
index 68f12fa..d8df11c 100644
--- a/operations/external/npd.c
+++ b/operations/external/npd.c
@@ -92,11 +92,11 @@ void npd_set_pixel_color_impl (NPDImage *image,
                                gint      y,
                                NPDColor *color)
 {
-  gint position = 4 * (y * image->width + x);
-  gint max = 4 * image->width * image->height;
-
-  if (position > 0 && position < max)
+  if (x > -1 && x < image->width &&
+      y > -1 && y < image->height)
     {
+      gint position = 4 * (y * image->width + x);
+
       image->buffer[position + 0] = color->r;
       image->buffer[position + 1] = color->g;
       image->buffer[position + 2] = color->b;
@@ -110,11 +110,11 @@ npd_get_pixel_color_impl (NPDImage *image,
                           gint      y,
                           NPDColor *color)
 {
-  gint position = 4 * (y * image->width + x);
-  gint max = 4 * image->width * image->height;
-
-  if (position > 0 && position < max)
+  if (x > -1 && x < image->width &&
+      y > -1 && y < image->height)
     {
+      gint position = 4 * (y * image->width + x);
+
       color->r = image->buffer[position + 0];
       color->g = image->buffer[position + 1];
       color->b = image->buffer[position + 2];


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]