rev 401 - trunk
[email protected] Mon, 2 May 2005 13:49:28 -0700 (PDT)
| Newsgroups | gmane.comp.printing.ghostscript.jbig2dec.cvs |
|---|---|
| Message-ID | <[email protected]> |
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 ret=
urn
negative values is the first argument is "less than" the second. The prev=
ious
one was fine for our purposes, but could cause problems if it was acciden=
tally
used by client applications.
Thanks to Ray Johnston for pointing this out.
Modified: trunk/memcmp.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- 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
=20
- Copyright (C) 2001-2002 artofcode LLC.
+ Copyright (C) 2001-2005 artofcode LLC.
=20
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.
=20
- $Id: memcmp.c,v 1.1 2002/08/05 17:10:44 giles Exp $
+ $Id$
*/
=20
#ifdef HAVE_CONFIG_H
@@ -26,24 +26,27 @@
=20
/*
* 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 un=
signed chars
+ * returns zero if the two strings are identical, otherwise returns -1 o=
r 1
+ * depending on the relative magnitude of the first differing elements,
+ * considered as unsigned chars
*/
=20
int memcmp(const void *b1, const void *b2, size_t len)
{
unsigned char *a, *b;
- unsigned char c;
size_t i;
=20
a =3D (unsigned char *)b1;
b =3D (unsigned char *)b2;
for(i =3D 0; i < len; i++) {
- c =3D *a - *b;
- if (c) return (int)c; /* strings differ */
+ if (*a !=3D *b) {
+ /* strings differ */
+ return (*a < *b) ? -1 : 1;
+ }
a++;
b++;
}
=20
- return 0; /* strings match */
+ /* strings match */
+ return 0;
}