Index: trunk/psphot/src/by_SN.c
===================================================================
--- trunk/psphot/src/by_SN.c	(revision 4115)
+++ trunk/psphot/src/by_SN.c	(revision 4129)
@@ -1,8 +1,9 @@
 # include "psphot.h"
 
+// sort by SN (descending)
 int by_SN (const void **a, const void **b)
 {
-    psSource *A = *a;
-    psSource *B = *b;
+    psSource *A = *(psSource **)a;
+    psSource *B = *(psSource **)b;
 
     psF32 fA = (A->moments == NULL) ? 0 : A->moments->SN;
@@ -10,6 +11,6 @@
 
     psF32 diff = fA - fB;
-    if (diff < FLT_EPSILON) return (-1);
-    if (diff > FLT_EPSILON) return (+1);
+    if (diff > FLT_EPSILON) return (-1);
+    if (diff < FLT_EPSILON) return (+1);
     return (0);
 }
