summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
inline | side by side (from parent 1:
0302f15)
This code is doing (foo - (char*)0) to convert foo from a pointer
value into a numeric value. Unfortunately, this is undefined
behaviour, which clang-14 is now warning about [1].
Cast to uintptr_t instead. Same result, but well-defined.
[1] cf. commit
0302f1532b66e9d09b70
salt_len = MIN(strcspn(salt, "$"), SHA256_SALT_LEN_MAX);
key_len = strlen(key);
salt_len = MIN(strcspn(salt, "$"), SHA256_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)
{
char *tmp = (char *)alloca(key_len + __alignof__(uint32_t));
key = copied_key =
memcpy(tmp + __alignof__(uint32_t)
- - (tmp - (char *)0) % __alignof__(uint32_t), key, key_len);
+ - ((uintptr_t) tmp) % __alignof__(uint32_t), key, key_len);
- 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)
{
char *tmp = (char *)alloca(salt_len + __alignof__(uint32_t));
salt = copied_salt =
memcpy(tmp + __alignof__(uint32_t)
- - (tmp - (char *)0) % __alignof__(uint32_t), salt, salt_len);
+ - ((uintptr_t) tmp) % __alignof__(uint32_t), salt, salt_len);
}
/* Prepare for the real work. */
}
/* Prepare for the real work. */
salt_len = MIN(strcspn(salt, "$"), SHA512_SALT_LEN_MAX);
key_len = strlen(key);
salt_len = MIN(strcspn(salt, "$"), SHA512_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 = (char *)alloca(key_len + __alignof__(uint64_t));
key = copied_key =
memcpy(tmp + __alignof__(uint64_t)
{
char *tmp = (char *)alloca(key_len + __alignof__(uint64_t));
key = copied_key =
memcpy(tmp + __alignof__(uint64_t)
- - (tmp - (char *)0) % __alignof__(uint64_t), key, key_len);
+ - ((uintptr_t) tmp) % __alignof__(uint64_t), key, key_len);
- 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)
{
char *tmp = (char *)alloca(salt_len + __alignof__(uint64_t));
salt = copied_salt =
memcpy(tmp + __alignof__(uint64_t)
- - (tmp - (char *)0) % __alignof__(uint64_t), salt, salt_len);
+ - ((uintptr_t) tmp) % __alignof__(uint64_t), salt, salt_len);
}
/* Prepare for the real work. */
}
/* Prepare for the real work. */