You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by "Ralf S. Engelschall" <rs...@engelschall.com> on 1998/10/23 09:15:12 UTC

[PATCH] ap_md5: unsigned char -> char !?

While I ported the DSO stuff to UnixWare 7 I recognized that I get a nasty
warning from the SVR4 compiler about a prototype mismatch. It's in util_md5.c,
line 114 where we pass a "const unsigned char *" argument to strlen() but
strlen() is (also on this platform) defined to use an argument of type "const
char *" (as ISO C requires). For GCC platforms this is no problem, but
other compilers complain here.

Usually we could cast the argument to strlen() to this type, but IMHO it's more
correct to change the string argument type of the ap_md5() function to "const
char *" and instead do the cast to "const unsigned char *" for the string
variable when passing to ap_md5_binary().

The patch is appended below. Give me your opinion.
Perhaps I'm wrong and it's more correct to cast the argument to strlen()
or to do nothing or whatever... 

Greetings,
                                       Ralf S. Engelschall
                                       rse@engelschall.com
                                       www.engelschall.com

Index: include/util_md5.h
===================================================================
RCS file: /e/apache/REPOS/apache-1.3/src/include/util_md5.h,v
retrieving revision 1.16
diff -u -r1.16 util_md5.h
--- util_md5.h	1998/09/06 17:12:18	1.16
+++ util_md5.h	1998/10/23 07:06:44
@@ -64,7 +64,7 @@
 
 #include "ap_md5.h"
 
-API_EXPORT(char *) ap_md5(pool *a, const unsigned char *string);
+API_EXPORT(char *) ap_md5(pool *a, const char *string);
 API_EXPORT(char *) ap_md5_binary(pool *a, const unsigned char *buf, int len);
 API_EXPORT(char *) ap_md5contextTo64(pool *p, AP_MD5_CTX * context);
 API_EXPORT(char *) ap_md5digest(pool *p, FILE *infile);
Index: main/util_md5.c
===================================================================
RCS file: /e/apache/REPOS/apache-1.3/src/main/util_md5.c,v
retrieving revision 1.15
diff -u -r1.15 util_md5.c
--- util_md5.c	1998/09/06 17:12:18	1.15
+++ util_md5.c	1998/10/23 07:06:23
@@ -109,9 +109,9 @@
     return ap_pstrdup(p, result);
 }
 
-API_EXPORT(char *) ap_md5(pool *p, const unsigned char *string)
+API_EXPORT(char *) ap_md5(pool *p, const char *string)
 {
-    return ap_md5_binary(p, string, strlen(string));
+    return ap_md5_binary(p, (const unsigned char *)string, strlen(string));
 }
 
 /* these portions extracted from mpack, John G. Myers - jgm+@cmu.edu */

Re: [PATCH] ap_md5: unsigned char -> char !?

Posted by Rodent of Unusual Size <Ke...@Golux.Com>.
Ralf S. Engelschall wrote:
> 
> Usually we could cast the argument to strlen() to this type, but IMHO it's more
> correct to change the string argument type of the ap_md5() function to "const
> char *" and instead do the cast to "const unsigned char *" for the string
> variable when passing to ap_md5_binary().

Actually, I disagree.  I think it is more appropriate to cast the
argument to strlen() than to change the datatype declaration of
the argument to the outer function.  The latter is concealing
what's actually needed for the sake of appeasing a lib routine
that doesn't care about the content of each byte (as long as it isn't
'\0') anyway.

#ken	P-)}

Ken Coar                    <http://Web.Golux.Com/coar/>
Apache Group member         <http://www.apache.org/>
"Apache Server for Dummies" <http://Web.Golux.Com/coar/ASFD/>