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]

md5-crypt.c warnings



In 2000-07-14 glibc, gcc -Wall gives warnings about discarded const in call to
memset.

md5-crypt.c: In function `__md5_crypt_r':
md5-crypt.c:229: warning: initialization discards qualifiers from pointer target type
md5-crypt.c:229: warning: initialization discards qualifiers from pointer target type
md5-crypt.c:229: warning: initialization discards qualifiers from pointer target type
md5-crypt.c:229: warning: passing arg 1 of `memset' discards qualifiers from pointer target type
md5-crypt.c:231: warning: initialization discards qualifiers from pointer target type
md5-crypt.c:231: warning: initialization discards qualifiers from pointer target type
md5-crypt.c:231: warning: initialization discards qualifiers from pointer target type
md5-crypt.c:231: warning: passing arg 1 of `memset' discards qualifiers from pointer target type

Here is a fix which doesn't need any casts.


2000-07-22  Bruno Haible  <haible@clisp.cons.org>

	* crypt/md5-crypt.c (__md5_crypt_r): Avoid gcc warnings: Use pointer
	variables, copied_key and copied_salt, instead of boolean variables.

*** glibc-cvs/crypt/md5-crypt.c.bak	Mon Jul 17 16:52:37 2000
--- glibc-cvs/crypt/md5-crypt.c	Mon Jul 24 18:21:23 2000
***************
*** 60,67 ****
    size_t key_len;
    size_t cnt;
    char *cp;
!   int key_copied = 0;
!   int salt_copied = 0;
  
    /* Find beginning of salt string.  The prefix should normally always
       be present.  Just in case it is not.  */
--- 60,67 ----
    size_t key_len;
    size_t cnt;
    char *cp;
!   char *copied_key = NULL;
!   char *copied_salt = NULL;
  
    /* Find beginning of salt string.  The prefix should normally always
       be present.  Just in case it is not.  */
***************
*** 75,95 ****
    if ((key - (char *) 0) % __alignof__ (md5_uint32) != 0)
      {
        char *tmp = (char *) alloca (key_len + __alignof__ (md5_uint32));
!       key = memcpy (tmp + __alignof__ (md5_uint32)
! 		    - (tmp - (char *) 0) % __alignof__ (md5_uint32),
! 		    key, key_len);
        assert ((key - (char *) 0) % __alignof__ (md5_uint32) == 0);
-       key_copied = 1;
      }
  
    if ((salt - (char *) 0) % __alignof__ (md5_uint32) != 0)
      {
        char *tmp = (char *) alloca (salt_len + __alignof__ (md5_uint32));
!       salt = memcpy (tmp + __alignof__ (md5_uint32)
! 		     - (tmp - (char *) 0) % __alignof__ (md5_uint32),
! 		     salt, salt_len);
        assert ((salt - (char *) 0) % __alignof__ (md5_uint32) == 0);
-       salt_copied = 1;
      }
  
    /* Prepare for the real work.  */
--- 75,95 ----
    if ((key - (char *) 0) % __alignof__ (md5_uint32) != 0)
      {
        char *tmp = (char *) alloca (key_len + __alignof__ (md5_uint32));
!       key = copied_key =
! 	memcpy (tmp + __alignof__ (md5_uint32)
! 		- (tmp - (char *) 0) % __alignof__ (md5_uint32),
! 		key, key_len);
        assert ((key - (char *) 0) % __alignof__ (md5_uint32) == 0);
      }
  
    if ((salt - (char *) 0) % __alignof__ (md5_uint32) != 0)
      {
        char *tmp = (char *) alloca (salt_len + __alignof__ (md5_uint32));
!       salt = copied_salt =
! 	memcpy (tmp + __alignof__ (md5_uint32)
! 		- (tmp - (char *) 0) % __alignof__ (md5_uint32),
! 		salt, salt_len);
        assert ((salt - (char *) 0) % __alignof__ (md5_uint32) == 0);
      }
  
    /* Prepare for the real work.  */
***************
*** 225,234 ****
    __md5_finish_ctx (&ctx, alt_result);
    memset (&ctx, '\0', sizeof (ctx));
    memset (&alt_ctx, '\0', sizeof (alt_ctx));
!   if (key_copied)
!     memset ((char *) key, '\0', key_len);
!   if (salt_copied)
!     memset ((char *) salt, '\0', salt_len);
  
    return buffer;
  }
--- 225,234 ----
    __md5_finish_ctx (&ctx, alt_result);
    memset (&ctx, '\0', sizeof (ctx));
    memset (&alt_ctx, '\0', sizeof (alt_ctx));
!   if (copied_key != NULL)
!     memset (copied_key, '\0', key_len);
!   if (copied_salt != NULL)
!     memset (copied_salt, '\0', salt_len);
  
    return buffer;
  }

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