Index: trunk/psphot/src/psphotSourceStats.c
===================================================================
--- trunk/psphot/src/psphotSourceStats.c	(revision 18039)
+++ trunk/psphot/src/psphotSourceStats.c	(revision 18241)
@@ -30,4 +30,8 @@
 
     psArray *peaks = detections->peaks;
+    if (!peaks) {
+        psError(PS_ERR_UNEXPECTED_NULL, false, "No peaks found!");
+        return NULL;
+    }
 
     sources = psArrayAllocEmpty (peaks->n);
@@ -37,6 +41,6 @@
     for (int i = 0; i < peaks->n; i++) {
 
-	pmPeak *peak = peaks->data[i];
-	if (peak->assigned) continue;
+        pmPeak *peak = peaks->data[i];
+        if (peak->assigned) continue;
 
         // create a new source, add peak
@@ -47,5 +51,5 @@
         pmSourceDefinePixels (source, readout, source->peak->x, source->peak->y, OUTER);
         if (!strcasecmp (breakPt, "PEAKS")) {
-	    peak->assigned = true;
+            peak->assigned = true;
             psArrayAdd (sources, 100, source);
             psFree (source);
@@ -55,5 +59,5 @@
         // skip faint sources for moments measurement
         if (source->peak->SN < MIN_SN) {
-	    peak->assigned = true;
+            peak->assigned = true;
             psArrayAdd (sources, 100, source);
             psFree (source);
@@ -62,5 +66,5 @@
 
         // measure a local sky value
-	// the local sky is now ignored; kept here for reference only
+        // the local sky is now ignored; kept here for reference only
         status = pmSourceLocalSky (source, PS_STAT_SAMPLE_MEDIAN, INNER, maskVal, mark);
         if (!status) {
@@ -85,5 +89,5 @@
         if (status) {
             // add to the source array
-	    peak->assigned = true;
+            peak->assigned = true;
             psArrayAdd (sources, 100, source);
             psFree (source);
@@ -99,5 +103,5 @@
         if (status) {
             // add to the source array
-	    peak->assigned = true;
+            peak->assigned = true;
             psArrayAdd (sources, 100, source);
             psFree (source);
