[jbig2-cvs] rev 401 - trunk

giles at ghostscript.com giles at ghostscript.com
Mon May 2 13:49:28 PDT 2005


Author: giles
Date: 2005-05-02 13:49:28 -0700 (Mon, 02 May 2005)
New Revision: 401

Modified:
   trunk/memcmp.c
Log:
Alter our portability fallback implementation of memcmp() to properly return
negative values is the first argument is "less than" the second. The previous
one was fine for our purposes, but could cause problems if it was accidentally
used by client applications.

Thanks to Ray Johnston for pointing this out.


Modified: trunk/memcmp.c
===================================================================
--- trunk/memcmp.c	2005-04-28 04:44:30 UTC (rev 400)
+++ trunk/memcmp.c	2005-05-02 20:49:28 UTC (rev 401)
@@ -1,7 +1,7 @@
 /*
     jbig2dec
     
-    Copyright (C) 2001-2002 artofcode LLC.
+    Copyright (C) 2001-2005 artofcode LLC.
     
     This software is distributed under license and may not
     be copied, modified or distributed except as expressly
@@ -13,7 +13,7 @@
     Artifex Software, Inc.,  101 Lucas Valley Road #110,
     San Rafael, CA  94903, U.S.A., +1(415)492-9861.
 
-    $Id: memcmp.c,v 1.1 2002/08/05 17:10:44 giles Exp $
+    $Id$
 */
 
 #ifdef HAVE_CONFIG_H
@@ -26,24 +26,27 @@
 
 /*
  * compares two byte strings 'a' and 'b', both assumed to be 'len' bytes long
- * returns zero if the two strings are identical, otherwise returns the difference
- * between the values of the first two differing bytes, considered as unsigned chars
+ * returns zero if the two strings are identical, otherwise returns -1 or 1
+ * depending on the relative magnitude of the first differing elements,
+ * considered as unsigned chars
  */
 
 int memcmp(const void *b1, const void *b2, size_t len)
 {
 	unsigned char *a, *b;
-	unsigned char c;
 	size_t i;
 
 	a = (unsigned char *)b1;
 	b = (unsigned char *)b2;
 	for(i = 0; i < len; i++) {
-		c = *a - *b;
-		if (c) return (int)c; /* strings differ */
+		if (*a != *b) {
+			 /* strings differ */
+			return (*a < *b) ? -1 : 1;
+		}
 		a++;
 		b++;
 	}
 
-	return 0; /* strings match */
+	/* strings match */
+	return 0;
 }



More information about the jbig2-cvs mailing list