Index: /trunk/psLib/src/imageops/psImageStats.c
===================================================================
--- /trunk/psLib/src/imageops/psImageStats.c	(revision 11759)
+++ /trunk/psLib/src/imageops/psImageStats.c	(revision 11760)
@@ -9,6 +9,6 @@
  *  @author GLG, MHPCC
  *
- *  @version $Revision: 1.104 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2007-02-13 03:01:23 $
+ *  @version $Revision: 1.105 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2007-02-13 03:08:17 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -183,5 +183,10 @@
     }
 
-    out = psVectorHistogram(out, junkData, NULL, junkMask, maskVal);
+    if (!psVectorHistogram(out, junkData, NULL, junkMask, maskVal)) {
+        psError(PS_ERR_UNKNOWN, false, "Unable to generate image histogram.\n");
+        psFree(junkMask);
+        psFree(junkData);
+        return false;
+    }
 
     psFree(junkMask);
Index: /trunk/psLib/src/math/psStats.c
===================================================================
--- /trunk/psLib/src/math/psStats.c	(revision 11759)
+++ /trunk/psLib/src/math/psStats.c	(revision 11760)
@@ -13,6 +13,6 @@
  * use ->min and ->max (PS_STAT_USE_RANGE)
  *
- *  @version $Revision: 1.200 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2007-02-07 23:52:54 $
+ *  @version $Revision: 1.201 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2007-02-13 03:08:17 $
  *
  *  Copyright 2006 IfA, University of Hawaii
@@ -87,9 +87,9 @@
 /******************************************************************************
 MISC PRIVATE STATISTICAL FUNCTIONS
- 
+
 NOTE: it is assumed that any call to these statistical functions will have
 been preceded by a call to the psVectorStats() function.  Various sanity tests
 will only be performed in psVectorStats().
- 
+
 For many of these private stats routines, it is possible that there are no acceptable elements
 in the input vector (if no elements lie within range, or there are no unmasked elements, or the
@@ -106,8 +106,8 @@
 mean of the input vector.  If there was a problem with the mean calculation,
 this routine sets stats->sampleMean to NAN.
- 
+
 using the method below, with a single loop for various options costs only a small amount and is
 much easier to debug. running 10000 tests of 1000 point vectors for the two methods gives:
- 
+
                      separate    single          w/errors
 (mask: 0, range: 0): 0.067 sec  0.073 sec (10%)  0.072 sec
@@ -115,7 +115,7 @@
 (mask: 0, range: 0): 0.136 sec  0.162 sec (20%)  0.170 sec
 (mask: 1, range: 0): 0.177 sec  0.181 sec ( 2%)  0.198 sec
- 
+
 (effect of errors not tested)
- 
+
 To optmize this, use a macro and ifdef in or out the three states (errors, mask, range)
 *****************************************************************************/
@@ -320,8 +320,8 @@
 Returns
     NULL
- 
+
 using the method below, with a single loop for various options costs only a small amount and is
 much easier to debug. running 10000 tests of 1000 point vectors for the two methods gives:
- 
+
                      single
 (mask: 0, range: 0): 0.193 sec
@@ -329,5 +329,5 @@
 (mask: 0, range: 0): 0.349 sec
 (mask: 1, range: 0): 0.401 sec
- 
+
 *****************************************************************************/
 static bool vectorSampleStdev(const psVector* myVector,
@@ -408,5 +408,5 @@
 vectorClippedStats(myVector, errors, maskInput, maskValInput, stats): calculates the
 clipped stats (mean or stdev) of the input vector.
- 
+
 Inputs
     myVector
@@ -557,5 +557,5 @@
 vectorRobustStats(myVector, maskInput, maskValInput, stats): This is the new
 version of the robust stats routine.
- 
+
 XXX: MUST DO: If the errors in the input values are known, then the same
 approach is used, except that the histograms become probability density
@@ -567,7 +567,7 @@
 each input value contributes constant area. Then the robust median and
 standard deviation are estimated in the same manner as above.
- 
+
 XXX: Check for errors in psLib routines that we call.
- 
+
 XXX: Review and ensure that all memory is free'ed at premature exits.
 *****************************************************************************/
@@ -666,5 +666,10 @@
         histogram = psHistogramAlloc(min, max, numBins);
         // XXXXX we need to consider this step if errors -> variance
-        histogram = psVectorHistogram(histogram, myVector, errors, mask, maskVal);
+        if (!psVectorHistogram(histogram, myVector, errors, mask, maskVal)) {
+            psError(PS_ERR_UNKNOWN, false, "Unable to generate histogram for robust statistics.\n");
+            psFree(histogram);
+            psFree(statsMinMax);
+            return false;
+        }
         if (psTraceGetLevel("psLib.math") >= 8) {
             PS_VECTOR_PRINT_F32(histogram->bounds);
@@ -980,5 +985,10 @@
 
         psHistogram *histogram = psHistogramAlloc(min, max, numBins); // A new histogram (without outliers)
-        histogram = psVectorHistogram(histogram, myVector, errors, mask, maskVal);
+        if (!psVectorHistogram(histogram, myVector, errors, mask, maskVal)) {
+            psError(PS_ERR_UNKNOWN, false, "Unable to generate histogram for fitted statistics.\n");
+            psFree(histogram);
+            psFree(statsMinMax);
+            return false;
+        }
         if (psTraceGetLevel("psLib.math") >= 8) {
             PS_VECTOR_PRINT_F32(histogram->nums);
@@ -1174,5 +1184,10 @@
 
         psHistogram *histogram = psHistogramAlloc(min, max, numBins); // A new histogram (without outliers)
-        histogram = psVectorHistogram(histogram, myVector, errors, mask, maskVal);
+        if (!psVectorHistogram(histogram, myVector, errors, mask, maskVal)) {
+            psError(PS_ERR_UNKNOWN, false, "Unable to generate histogram for fitted statistcs v2.\n");
+            psFree(histogram);
+            psFree(statsMinMax);
+            return false;
+        }
         if (psTraceGetLevel("psLib.math") >= 8) {
             PS_VECTOR_PRINT_F32(histogram->nums);
@@ -1382,5 +1397,10 @@
 
         psHistogram *histogram = psHistogramAlloc(min, max, numBins); // A new histogram (without outliers)
-        histogram = psVectorHistogram(histogram, myVector, errors, mask, maskVal);
+        if (!psVectorHistogram(histogram, myVector, errors, mask, maskVal)) {
+            psError(PS_ERR_UNKNOWN, false, "Unable to generate histogram for fitted statistics v3.\n");
+            psFree(histogram);
+            psFree(statsMinMax);
+            return false;
+        }
         if (psTraceGetLevel("psLib.math") >= 8) {
             PS_VECTOR_PRINT_F32(histogram->nums);
@@ -1594,5 +1614,5 @@
 robustHistogram with a Gaussian of width sigma.  It returns a psVector of the
 smoothed data.
- 
+
 XXX this function is unused
 *****************************************************************************/
@@ -1753,5 +1773,5 @@
 function which calls the above private stats functions based on what bits
 were set in stats->options.
- 
+
 Inputs
     in
@@ -1761,5 +1781,5 @@
 Returns
     The stats structure.
- 
+
 XXX: Should we free stats if the asserts fail? NO; we don't own it (RHL).
 *****************************************************************************/
@@ -2107,5 +2127,5 @@
 then determines for what value x does that quadratic f(x) = yVal (the input
 parameter).
- 
+
 *****************************************************************************/
 static psF32 fitQuadraticSearchForYThenReturnX(const psVector *xVec,
