about summary refs log tree commit diff
path: root/crypt
diff options
context:
space:
mode:
authorQihao Chencao <twose@qq.com>2022-06-28 16:57:55 +0800
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>2023-02-17 17:07:44 -0300
commitcc4d6614b5922c1104125b1f4d0850a88a551882 (patch)
treeaade315fd79153cf930e8dfd15581dcbdffea0b8 /crypt
parentdab63442791e334d592ce91827ffa9d14ca92ea9 (diff)
downloadglibc-cc4d6614b5922c1104125b1f4d0850a88a551882.tar.gz
glibc-cc4d6614b5922c1104125b1f4d0850a88a551882.tar.xz
glibc-cc4d6614b5922c1104125b1f4d0850a88a551882.zip
Use uintptr_t instead of performing pointer subtraction with a null pointer
Signed-off-by: Qihao Chencao <twose@qq.com>

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
Diffstat (limited to 'crypt')
-rw-r--r--crypt/md5-crypt.c12
-rw-r--r--crypt/sha256-crypt.c12
-rw-r--r--crypt/sha512-crypt.c12
3 files changed, 18 insertions, 18 deletions
diff --git a/crypt/md5-crypt.c b/crypt/md5-crypt.c
index 791a59767d..0cc597a7f2 100644
--- a/crypt/md5-crypt.c
+++ b/crypt/md5-crypt.c
@@ -110,7 +110,7 @@ __md5_crypt_r (const char *key, const char *salt, char *buffer, int buflen)
   salt_len = MIN (strcspn (salt, "$"), 8);
   key_len = strlen (key);
 
-  if ((key - (char *) 0) % __alignof__ (md5_uint32) != 0)
+  if (((uintptr_t) key) % __alignof__ (md5_uint32) != 0)
     {
       char *tmp;
 
@@ -125,19 +125,19 @@ __md5_crypt_r (const char *key, const char *salt, char *buffer, int buflen)
 
       key = copied_key =
 	memcpy (tmp + __alignof__ (md5_uint32)
-		- (tmp - (char *) 0) % __alignof__ (md5_uint32),
+		- ((uintptr_t) tmp) % __alignof__ (md5_uint32),
 		key, key_len);
-      assert ((key - (char *) 0) % __alignof__ (md5_uint32) == 0);
+      assert (((uintptr_t) key) % __alignof__ (md5_uint32) == 0);
     }
 
-  if ((salt - (char *) 0) % __alignof__ (md5_uint32) != 0)
+  if (((uintptr_t) salt) % __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),
+		- ((uintptr_t) tmp) % __alignof__ (md5_uint32),
 		salt, salt_len);
-      assert ((salt - (char *) 0) % __alignof__ (md5_uint32) == 0);
+      assert (((uintptr_t) salt) % __alignof__ (md5_uint32) == 0);
     }
 
 #ifdef USE_NSS
diff --git a/crypt/sha256-crypt.c b/crypt/sha256-crypt.c
index 2a2b356d9a..1ef16af80f 100644
--- a/crypt/sha256-crypt.c
+++ b/crypt/sha256-crypt.c
@@ -142,7 +142,7 @@ __sha256_crypt_r (const char *key, const char *salt, char *buffer, int buflen)
   salt_len = MIN (strcspn (salt, "$"), SALT_LEN_MAX);
   key_len = strlen (key);
 
-  if ((key - (char *) 0) % __alignof__ (uint32_t) != 0)
+  if (((uintptr_t) key) % __alignof__ (uint32_t) != 0)
     {
       char *tmp;
 
@@ -157,20 +157,20 @@ __sha256_crypt_r (const char *key, const char *salt, char *buffer, int buflen)
 
       key = copied_key =
 	memcpy (tmp + __alignof__ (uint32_t)
-		- (tmp - (char *) 0) % __alignof__ (uint32_t),
+		- ((uintptr_t) tmp) % __alignof__ (uint32_t),
 		key, key_len);
-      assert ((key - (char *) 0) % __alignof__ (uint32_t) == 0);
+      assert (((uintptr_t) key) % __alignof__ (uint32_t) == 0);
     }
 
-  if ((salt - (char *) 0) % __alignof__ (uint32_t) != 0)
+  if (((uintptr_t) salt) % __alignof__ (uint32_t) != 0)
     {
       char *tmp = (char *) alloca (salt_len + __alignof__ (uint32_t));
       alloca_used += salt_len + __alignof__ (uint32_t);
       salt = copied_salt =
 	memcpy (tmp + __alignof__ (uint32_t)
-		- (tmp - (char *) 0) % __alignof__ (uint32_t),
+		- ((uintptr_t) tmp) % __alignof__ (uint32_t),
 		salt, salt_len);
-      assert ((salt - (char *) 0) % __alignof__ (uint32_t) == 0);
+      assert (((uintptr_t) salt) % __alignof__ (uint32_t) == 0);
     }
 
 #ifdef USE_NSS
diff --git a/crypt/sha512-crypt.c b/crypt/sha512-crypt.c
index 9deb31ce99..b592eb0976 100644
--- a/crypt/sha512-crypt.c
+++ b/crypt/sha512-crypt.c
@@ -142,7 +142,7 @@ __sha512_crypt_r (const char *key, const char *salt, char *buffer, int buflen)
   salt_len = MIN (strcspn (salt, "$"), SALT_LEN_MAX);
   key_len = strlen (key);
 
-  if ((key - (char *) 0) % __alignof__ (uint64_t) != 0)
+  if (((uintptr_t) key) % __alignof__ (uint64_t) != 0)
     {
       char *tmp;
 
@@ -157,19 +157,19 @@ __sha512_crypt_r (const char *key, const char *salt, char *buffer, int buflen)
 
       key = copied_key =
 	memcpy (tmp + __alignof__ (uint64_t)
-		- (tmp - (char *) 0) % __alignof__ (uint64_t),
+		- ((uintptr_t) tmp) % __alignof__ (uint64_t),
 		key, key_len);
-      assert ((key - (char *) 0) % __alignof__ (uint64_t) == 0);
+      assert (((uintptr_t) key) % __alignof__ (uint64_t) == 0);
     }
 
-  if ((salt - (char *) 0) % __alignof__ (uint64_t) != 0)
+  if (((uintptr_t) salt) % __alignof__ (uint64_t) != 0)
     {
       char *tmp = (char *) alloca (salt_len + __alignof__ (uint64_t));
       salt = copied_salt =
 	memcpy (tmp + __alignof__ (uint64_t)
-		- (tmp - (char *) 0) % __alignof__ (uint64_t),
+		- ((uintptr_t) tmp) % __alignof__ (uint64_t),
 		salt, salt_len);
-      assert ((salt - (char *) 0) % __alignof__ (uint64_t) == 0);
+      assert (((uintptr_t) salt) % __alignof__ (uint64_t) == 0);
     }
 
 #ifdef USE_NSS