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



commit 3de5bc94806baa65fe4ff51904d44a1c9a3c67d5
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]