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]

Re: glibc 2.1.96 (sysdeps/i386/i486/bits/string.h has a bug)


The strcmp implementation has a problem. If either of arguments is of
type (void*) then the __strcmp_xx macros will dereference this void
pointer with all the consequences. And, say, bind-9 can't be
compiled... So, here is the straightforward patch.



--- glibc-2.1.95-/sysdeps/i386/i486/bits/string.h	Thu Sep 21 02:51:57 2000
+++ glibc-2.1.95-/sysdeps/i386/i486/bits/string+.h	Thu Nov  2 23:33:11 2000
@@ -1065,49 +1065,49 @@
 			: __strcmp_gg (s1, s2)))))
 
 #define __strcmp_cc(s1, s2, l) \
-  (__extension__ ({ register int __result = ((unsigned char) (s1)[0]	      \
-					     - (unsigned char) (s2)[0]);      \
+  (__extension__ ({ register int __result = (((unsigned char*) (s1))[0]	      \
+					     - ((unsigned char*) (s2))[0]);   \
 		    if (l > 0 && __result == 0)				      \
 		      {							      \
-			__result = ((unsigned char) (s1)[1]		      \
-				    - (unsigned char) (s2)[1]);		      \
+			__result = (((unsigned char*) (s1))[1]		      \
+				    - ((unsigned char*) (s2))[1]);	      \
 			if (l > 1 && __result == 0)			      \
 			  {						      \
-			    __result = ((unsigned char) (s1)[2]		      \
-					- (unsigned char) (s2)[2]);	      \
+			    __result = (((unsigned char*) (s1))[2]	      \
+					- ((unsigned char*) (s2))[2]);	      \
 			    if (l > 2 && __result == 0)			      \
-			      __result = ((unsigned char) (s1)[3]	      \
-					  - (unsigned char) (s2)[3]);	      \
+			      __result = (((unsigned char*) (s1))[3]	      \
+					  - ((unsigned char*) (s2))[3]);      \
 			  }						      \
 		      }							      \
 		    __result; }))
 
 #define __strcmp_cg(s1, s2, l1) \
   (__extension__ ({ __const unsigned char *__s2 = (unsigned char *) (s2);     \
-		    register int __result = (unsigned char) (s1)[0] - __s2[0];\
+		    register int __result = ((unsigned char*) (s1))[0] - __s2[0];\
 		    if (l1 > 0 && __result == 0)			      \
 		      {							      \
-			__result = (unsigned char) (s1)[1] - __s2[1];	      \
+			__result = ((unsigned char*) (s1))[1] - __s2[1];      \
 			if (l1 > 1 && __result == 0)			      \
 			  {						      \
-			    __result = (unsigned char) (s1)[2] - __s2[2];     \
+			    __result = ((unsigned char*) (s1))[2] - __s2[2];  \
 			    if (l1 > 2 && __result == 0)		      \
-			      __result = (unsigned char) (s1)[3] - __s2[3];   \
+			      __result = ((unsigned char*) (s1))[3] - __s2[3];\
 			  }						      \
 		      }							      \
 		    __result; }))
 
 #define __strcmp_gc(s1, s2, l2) \
   (__extension__ ({ __const unsigned char *__s1 = (unsigned char *) (s1);     \
-		    register int __result = __s1[0] - (unsigned char) (s2)[0];\
+		    register int __result = __s1[0] - ((unsigned char*) (s2))[0];\
 		    if (l2 > 0 && __result == 0)			      \
 		      {							      \
-			__result = __s1[1] - (unsigned char) (s2)[1];	      \
+			__result = __s1[1] - ((unsigned char*) (s2))[1];      \
 			if (l2 > 1 && __result == 0)			      \
 			  {						      \
-			    __result = __s1[2] - (unsigned char) (s2)[2];     \
+			    __result = __s1[2] - ((unsigned char*) (s2))[2];  \
 			    if (l2 > 2 && __result == 0)		      \
-			      __result = __s1[3] - (unsigned char) (s2)[3];   \
+			      __result = __s1[3] - ((unsigned char*) (s2))[3];\
 			  }						      \
 		      }							      \
 		    __result; }))



By the way, what were the reasons to make these 3 macros which all do
the same? It seems that one inline function would look better...

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