Skip to content

Commit d83ec6c

Browse files
committed
Finally fixing the crypt sha apis by removing the said subtraction by casting instead.
While at it fixing werror level on phpdbg too.
1 parent d66d477 commit d83ec6c

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

ext/standard/crypt_sha256.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -371,15 +371,15 @@ char * php_sha256_crypt_r(const char *key, const char *salt, char *buffer, int b
371371
salt_len = MIN(strcspn(salt, "$"), SALT_LEN_MAX);
372372
key_len = strlen(key);
373373

374-
if ((key - (char *) 0) % __alignof__ (uint32_t) != 0) {
374+
if ((uintptr_t)key % __alignof__ (uint32_t) != 0) {
375375
char *tmp = (char *) alloca(key_len + __alignof__(uint32_t));
376-
key = copied_key = memcpy(tmp + __alignof__(uint32_t) - (tmp - (char *) 0) % __alignof__(uint32_t), key, key_len);
376+
key = copied_key = memcpy(tmp + __alignof__(uint32_t) - (uintptr_t)tmp % __alignof__(uint32_t), key, key_len);
377377
}
378378

379-
if ((salt - (char *) 0) % __alignof__(uint32_t) != 0) {
379+
if ((uintptr_t)salt % __alignof__(uint32_t) != 0) {
380380
char *tmp = (char *) alloca(salt_len + 1 + __alignof__(uint32_t));
381381
salt = copied_salt =
382-
memcpy(tmp + __alignof__(uint32_t) - (tmp - (char *) 0) % __alignof__ (uint32_t), salt, salt_len);
382+
memcpy(tmp + __alignof__(uint32_t) - (uintptr_t)tmp % __alignof__ (uint32_t), salt, salt_len);
383383
copied_salt[salt_len] = 0;
384384
}
385385

ext/standard/crypt_sha512.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -405,15 +405,15 @@ php_sha512_crypt_r(const char *key, const char *salt, char *buffer, int buflen)
405405
salt_len = MIN(strcspn(salt, "$"), SALT_LEN_MAX);
406406
key_len = strlen(key);
407407

408-
if ((key - (char *) 0) % __alignof__ (uint64_t) != 0) {
408+
if ((uintptr_t)key % __alignof__ (uint64_t) != 0) {
409409
char *tmp = (char *) alloca (key_len + __alignof__ (uint64_t));
410410
key = copied_key =
411-
memcpy(tmp + __alignof__(uint64_t) - (tmp - (char *) 0) % __alignof__(uint64_t), key, key_len);
411+
memcpy(tmp + __alignof__(uint64_t) - (uintptr_t)tmp % __alignof__(uint64_t), key, key_len);
412412
}
413413

414-
if ((salt - (char *) 0) % __alignof__ (uint64_t) != 0) {
414+
if ((uintptr_t)salt % __alignof__ (uint64_t) != 0) {
415415
char *tmp = (char *) alloca(salt_len + 1 + __alignof__(uint64_t));
416-
salt = copied_salt = memcpy(tmp + __alignof__(uint64_t) - (tmp - (char *) 0) % __alignof__(uint64_t), salt, salt_len);
416+
salt = copied_salt = memcpy(tmp + __alignof__(uint64_t) - (uintptr_t)tmp % __alignof__(uint64_t), salt, salt_len);
417417
copied_salt[salt_len] = 0;
418418
}
419419

sapi/phpdbg/phpdbg.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -910,7 +910,7 @@ static ssize_t phpdbg_stdiop_write(php_stream *stream, const char *buf, size_t c
910910
while (data->fd >= 0) {
911911
struct stat stat[3];
912912
memset(stat, 0, sizeof(stat));
913-
if (((fstat(fileno(stderr), &stat[2]) < 0) & (fstat(fileno(stdout), &stat[0]) < 0)) | (fstat(data->fd, &stat[1]) < 0)) {
913+
if (((fstat(fileno(stderr), &stat[2]) < 0) && (fstat(fileno(stdout), &stat[0]) < 0)) || (fstat(data->fd, &stat[1]) < 0)) {
914914
break;
915915
}
916916

0 commit comments

Comments
 (0)