[vhffs-dev] [1285] ok, substract unsigned values is always a bad idea if the result can be < 0 :- )

[ Thread Index | Date Index | More vhffs.org/vhffs-dev Archives ]


Revision: 1285
Author:   gradator
Date:     2008-10-14 19:14:29 +0200 (Tue, 14 Oct 2008)

Log Message:
-----------
ok, substract unsigned values is always a bad idea if the result can be < 0 :-)

PLEASE BLAME ME (I love that).

Modified Paths:
--------------
    trunk/vhffs-fssync/vhffsfssync_master.c


Modified: trunk/vhffs-fssync/vhffsfssync_master.c
===================================================================
--- trunk/vhffs-fssync/vhffsfssync_master.c	2008-10-14 10:53:02 UTC (rev 1284)
+++ trunk/vhffs-fssync/vhffsfssync_master.c	2008-10-14 17:14:29 UTC (rev 1285)
@@ -259,12 +259,28 @@
 	vhffsfssync_net_message *first = (vhffsfssync_net_message*)a;
 	vhffsfssync_net_message *second = (vhffsfssync_net_message*)b;
 
-	// lowest priority is preferred
-	if(first->msg_priority != second->msg_priority)
-		return first->msg_priority - second->msg_priority;
+	if(first->msg_priority != second->msg_priority) {
+		// lowest priority is preferred
+		if(first->msg_priority < second->msg_priority)
+			return -1;
+		else
+			return 1;
 
-	// lowest order is preferred
-	return first->msg_order - second->msg_order;
+		// Don't expect to do 'return first->msg_priority - second->msg_priority;'
+		// even if this seems more convenient, because msg->msg_priority is
+		// an __unsigned__ long integer, you also have to return a signed long integer value
+	}
+	else {
+		// lowest order is preferred
+		if(first->msg_order < second->msg_order)
+			return -1;
+		else
+			return 1;
+
+		// Don't expect to do 'return first->msg_order - second->msg_order;'
+		// for the same reasons explained above
+	}
+	return 0;
 }
 
 


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/