Index: trunk/psLib/src/imageops/psImageConvolve.c
===================================================================
--- trunk/psLib/src/imageops/psImageConvolve.c	(revision 28405)
+++ trunk/psLib/src/imageops/psImageConvolve.c	(revision 30595)
@@ -67,5 +67,8 @@
 }
 
-psKernel *psKernelAlloc(int xMin, int xMax, int yMin, int yMax)
+psKernel *p_psKernelAlloc(const char *file,
+			  unsigned int lineno,
+			  const char *func,
+			  int xMin, int xMax, int yMin, int yMax)
 {
     // Check the inputs to make sure max > min; if not, switch.
@@ -91,5 +94,5 @@
     int numCols = xMax - xMin + 1;      // Number of columns for kernel image
 
-    psKernel *kernel = psAlloc(sizeof(psKernel)); // The kernel, to be returned
+    psKernel *kernel = p_psAlloc(file, lineno, func, sizeof(psKernel)); // The kernel, to be returned
     psMemSetDeallocator(kernel,(psFreeFunc)kernelFree);
 
@@ -272,7 +275,9 @@
     float threshold = sumKernel * (1.0 - frac); // Threshold for truncation
 
+    int truncateRadius = maxSize;	// Truncation radius
+    bool truncate = false;
+
     // Find truncation size
-    int truncate = 0;                     // Truncation radius
-    for (int radius = 1; truncate == 0 && radius < maxSize; radius++) {
+    for (int radius = 1; !truncate && (radius < maxSize); radius++) {
         int uMin = PS_MAX(-radius, xMin);
         int uMax = PS_MIN(radius, xMax);
@@ -290,11 +295,13 @@
             }
         }
+	// This is the truncation radius
         if (sum > threshold) {
-            // This is the truncation radius
-            truncate = radius;
-        }
-    }
-    if (truncate == maxSize) {
-        // No truncation possible
+	    truncate = true;
+            truncateRadius = radius;
+        }
+    }
+
+    // Do nothing if no truncation is possible
+    if (!truncate) {
         return true;
     }
@@ -302,9 +309,9 @@
     // Truncate the kernel
     {
-        int uMin = PS_MAX(-truncate, xMin);
-        int uMax = PS_MIN(truncate, xMax);
-        int vMin = PS_MAX(-truncate, yMin);
-        int vMax = PS_MIN(truncate, yMax);
-        int r2 = PS_SQR(truncate);
+        int uMin = PS_MAX(-truncateRadius, xMin);
+        int uMax = PS_MIN(truncateRadius, xMax);
+        int vMin = PS_MAX(-truncateRadius, yMin);
+        int vMax = PS_MIN(truncateRadius, yMax);
+        int r2 = PS_SQR(truncateRadius);
         for (int v = vMin; v <= vMax; v++) {
             int v2 = PS_SQR(v);
@@ -317,8 +324,8 @@
         }
     }
-    kernel->xMin = PS_MAX(-truncate, kernel->xMin);
-    kernel->xMax = PS_MIN(truncate, kernel->xMax);
-    kernel->yMin = PS_MAX(-truncate, kernel->yMin);
-    kernel->yMax = PS_MIN(truncate, kernel->yMax);
+    kernel->xMin = PS_MAX(-truncateRadius, kernel->xMin);
+    kernel->xMax = PS_MIN(truncateRadius, kernel->xMax);
+    kernel->yMin = PS_MAX(-truncateRadius, kernel->yMin);
+    kernel->yMax = PS_MIN(truncateRadius, kernel->yMax);
 
     return true;
