diff options
author | Sven Linker <sven.linker@kernkonzept.com> | 2024-02-20 14:26:46 +0100 |
---|---|---|
committer | Waldemar Brodkorb <wbx@openadk.org> | 2024-02-20 19:37:25 +0100 |
commit | a908621a934643f51a58042abcf1d1e42e281943 (patch) | |
tree | 8b5b2dfcbca4f721bb42ef6048cab76204ddab86 /libcrypt/sha256-crypt.c | |
parent | 0f4669a6ec932dd6d037810d64286ba2f4e02ee0 (diff) |
Replace null subtraction with cast
Clang warns about null-pointer subtractions, which are undefined
behavior per the C standards. Replace the subtractions with
explicit casts to `uintptr_t`.
Diffstat (limited to 'libcrypt/sha256-crypt.c')
-rw-r--r-- | libcrypt/sha256-crypt.c | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/libcrypt/sha256-crypt.c b/libcrypt/sha256-crypt.c index 81bbe6ae6..b2ab62e48 100644 --- a/libcrypt/sha256-crypt.c +++ b/libcrypt/sha256-crypt.c @@ -104,24 +104,24 @@ __sha256_crypt_r (const char *key, 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 = (char *) alloca (key_len + __alignof__ (uint32_t)); 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)); 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); } struct sha256_ctx ctx; |