This is the mail archive of the
libc-alpha@sources.redhat.com
mailing list for the glibc project.
A bug in strverscmp.c?
- To: GNU C Library <libc-alpha at sourceware dot cygnus dot com>
- Subject: A bug in strverscmp.c?
- From: "H . J . Lu" <hjl at valinux dot com>
- Date: Thu, 1 Feb 2001 09:48:46 -0800
This testcase prints "-45". I was expecting a positive number. How about this
patch?
--
H.J. Lu (hjl@valinux.com)
--
#include <string.h>
#include <stdio.h>
main ()
{
printf ("%d\n", strverscmp ("2.8", "2.8-0.4"));
}
---
2001-02-01 H.J. Lu <hjl@gnu.org>
* string/strverscmp.c (__strverscmp): Treat '\0' as the
lowest version.
Index: string/strverscmp.c
===================================================================
RCS file: /work/cvs/gnu/glibc/string/strverscmp.c,v
retrieving revision 1.1.1.1
diff -u -p -r1.1.1.1 strverscmp.c
--- string/strverscmp.c 2000/05/21 21:11:27 1.1.1.1
+++ string/strverscmp.c 2001/02/01 17:45:55
@@ -83,7 +83,7 @@ __strverscmp (s1, s2)
/* Hint: '0' is a digit too. */
state = S_N | ((c1 == '0') + (isdigit (c1) != 0));
- while ((diff = c1 - c2) == 0 && c1 != '\0')
+ while ((diff = c1 ? c1 - c2 : c2) == 0 && c1 != '\0')
{
state = next_state[state];
c1 = *p1++;