This is the mail archive of the libc-alpha@sources.redhat.com mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

A bug in strverscmp.c?


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++;

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]