Skip to content

Commit aa8b9b9

Browse files
committed
crypt_sha256/crypt_sha512, fix build with more recent versions of clang (> 12).
clang picks up the address subtraction to null as UB, but the implementations are based on glibc. `error: performing pointer subtraction with a null pointer has undefined behavior [-Werror,-Wnull-pointer-subtraction] if ((key - (char *) 0) % __alignof__ (uint64_t) != 0) {`
1 parent d66d477 commit aa8b9b9

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

ext/standard/crypt_sha256.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,11 @@ static const char sha256_rounds_prefix[] = "rounds=";
322322
static const char b64t[64] =
323323
"./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
324324

325+
#if defined(__clang__) && __clang_major__ > 12
326+
#pragma clang diagnostic push
327+
#pragma clang diagnostic ignored "-Wnull-pointer-subtraction"
328+
#endif
329+
325330
char * php_sha256_crypt_r(const char *key, const char *salt, char *buffer, int buflen)
326331
{
327332
#ifdef PHP_WIN32
@@ -575,6 +580,9 @@ char * php_sha256_crypt_r(const char *key, const char *salt, char *buffer, int b
575580
return buffer;
576581
}
577582

583+
#if defined(__clang__) && __clang_major__ > 12
584+
#pragma clang diagnostic pop
585+
#endif
578586

579587
/* This entry point is equivalent to the `crypt' function in Unix
580588
libcs. */

ext/standard/crypt_sha512.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,10 @@ static const char sha512_rounds_prefix[] = "rounds=";
355355
static const char b64t[64] =
356356
"./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
357357

358+
#if defined(__clang__) && __clang_major__ > 12
359+
#pragma clang diagnostic push
360+
#pragma clang diagnostic ignored "-Wnull-pointer-subtraction"
361+
#endif
358362

359363
char *
360364
php_sha512_crypt_r(const char *key, const char *salt, char *buffer, int buflen) {
@@ -622,6 +626,10 @@ php_sha512_crypt_r(const char *key, const char *salt, char *buffer, int buflen)
622626
return buffer;
623627
}
624628

629+
#if defined(__clang__) && __clang_major__ > 12
630+
#pragma clang diagnostic pop
631+
#endif
632+
625633

626634
/* This entry point is equivalent to the `crypt' function in Unix
627635
libcs. */

0 commit comments

Comments
 (0)