From d00dd6031e859d04c652077e8440bfe92ded8ba7 Mon Sep 17 00:00:00 2001 From: "Christoph M. Becker" Date: Sat, 18 Jan 2025 12:33:58 +0100 Subject: [PATCH 1/5] Address more Clang warnings We prefer clean solutions (such as declaring the proper type in the first place, or introducing a portable format specifier) where easily possible, but resort to casts otherwise. --- ext/com_dotnet/com_handlers.c | 2 +- ext/com_dotnet/com_wrapper.c | 2 +- ext/ffi/ffi.c | 3 ++- ext/gd/libgd/gd_interpolation.c | 2 +- ext/libxml/libxml.c | 4 ++-- ext/mysqlnd/mysqlnd_auth.c | 10 +++++----- ext/mysqlnd/mysqlnd_connection.c | 2 +- ext/openssl/xp_ssl.c | 2 +- ext/standard/streamsfuncs.c | 2 +- main/php_network.h | 2 ++ main/streams/plain_wrapper.c | 2 +- win32/registry.c | 4 ++-- win32/wsyslog.c | 4 ++-- 13 files changed, 22 insertions(+), 19 deletions(-) diff --git a/ext/com_dotnet/com_handlers.c b/ext/com_dotnet/com_handlers.c index a5c68bb7b9987..fcbae4e34621f 100644 --- a/ext/com_dotnet/com_handlers.c +++ b/ext/com_dotnet/com_handlers.c @@ -353,7 +353,7 @@ static zend_function *com_method_get(zend_object **object_ptr, zend_string *name ITypeComp_Release(bindptr.lptcomp); break; - case DESCKIND_NONE: + default: break; } if (TI) { diff --git a/ext/com_dotnet/com_wrapper.c b/ext/com_dotnet/com_wrapper.c index 6e885fa802e9f..df39239022455 100644 --- a/ext/com_dotnet/com_wrapper.c +++ b/ext/com_dotnet/com_wrapper.c @@ -424,7 +424,7 @@ static void generate_dispids(php_dispatchex *disp) zend_string *name = NULL; zval *tmp, tmp2; int keytype; - zend_long pid; + zend_ulong pid; if (disp->dispid_to_name == NULL) { ALLOC_HASHTABLE(disp->dispid_to_name); diff --git a/ext/ffi/ffi.c b/ext/ffi/ffi.c index c8e0035b3ac91..cac7b1b54b7c6 100644 --- a/ext/ffi/ffi.c +++ b/ext/ffi/ffi.c @@ -900,9 +900,10 @@ static zend_always_inline zend_string *zend_ffi_mangled_func_name(zend_string *n case FFI_VECTORCALL_PARTIAL: return strpprintf(0, "%s@@%zu", ZSTR_VAL(name), zend_ffi_arg_size(type)); # endif + default: + return zend_string_copy(name); } #endif - return zend_string_copy(name); } /* }}} */ diff --git a/ext/gd/libgd/gd_interpolation.c b/ext/gd/libgd/gd_interpolation.c index 9b0551c7afc8e..123769313e246 100644 --- a/ext/gd/libgd/gd_interpolation.c +++ b/ext/gd/libgd/gd_interpolation.c @@ -62,7 +62,7 @@ #include "gdhelpers.h" #include "gd_intern.h" -#ifdef _MSC_VER +#if defined(_MSC_VER) && !defined(__clang__) # pragma optimize("t", on) # include #endif diff --git a/ext/libxml/libxml.c b/ext/libxml/libxml.c index 40b6326ba72c4..94704d09e463e 100644 --- a/ext/libxml/libxml.c +++ b/ext/libxml/libxml.c @@ -433,9 +433,9 @@ static void *php_libxml_streams_IO_open_wrapper(const char *filename, const char if (strncasecmp(resolved_path, "file:/", pre_len) == 0 && '/' != resolved_path[pre_len]) { - xmlChar *tmp = xmlStrdup(resolved_path + pre_len); + xmlChar *tmp = xmlStrdup(BAD_CAST (resolved_path + pre_len)); xmlFree(resolved_path); - resolved_path = tmp; + resolved_path = (char *) tmp; } } #endif diff --git a/ext/mysqlnd/mysqlnd_auth.c b/ext/mysqlnd/mysqlnd_auth.c index ea9755c982ed8..3a30b1458dea0 100644 --- a/ext/mysqlnd/mysqlnd_auth.c +++ b/ext/mysqlnd/mysqlnd_auth.c @@ -746,7 +746,7 @@ static mysqlnd_rsa_t mysqlnd_sha256_get_rsa_from_pem(const char *buf, size_t len) { BCRYPT_KEY_HANDLE ret = 0; - LPSTR der_buf = NULL; + BYTE *der_buf = NULL; DWORD der_len; CERT_PUBLIC_KEY_INFO *key_info = NULL; DWORD key_info_len; @@ -789,7 +789,7 @@ mysqlnd_sha256_public_encrypt(MYSQLND_CONN_DATA * conn, mysqlnd_rsa_t server_pub ZeroMemory(&padding_info, sizeof padding_info); padding_info.pszAlgId = BCRYPT_SHA1_ALGORITHM; - if (BCryptEncrypt((BCRYPT_KEY_HANDLE) server_public_key, xor_str, passwd_len + 1, &padding_info, + if (BCryptEncrypt((BCRYPT_KEY_HANDLE) server_public_key, (zend_uchar *) xor_str, passwd_len + 1, &padding_info, NULL, 0, NULL, 0, &server_public_key_len, BCRYPT_PAD_OAEP)) { DBG_RETURN(0); } @@ -809,7 +809,7 @@ mysqlnd_sha256_public_encrypt(MYSQLND_CONN_DATA * conn, mysqlnd_rsa_t server_pub *auth_data_len = server_public_key_len; ret = malloc(*auth_data_len); - if (BCryptEncrypt((BCRYPT_KEY_HANDLE) server_public_key, xor_str, passwd_len + 1, &padding_info, + if (BCryptEncrypt((BCRYPT_KEY_HANDLE) server_public_key, (zend_uchar *) xor_str, passwd_len + 1, &padding_info, NULL, 0, ret, server_public_key_len, &server_public_key_len, BCRYPT_PAD_OAEP)) { BCryptDestroyKey((BCRYPT_KEY_HANDLE) server_public_key); DBG_RETURN(0); @@ -1052,7 +1052,7 @@ mysqlnd_caching_sha2_public_encrypt(MYSQLND_CONN_DATA * conn, mysqlnd_rsa_t serv ZeroMemory(&padding_info, sizeof padding_info); padding_info.pszAlgId = BCRYPT_SHA1_ALGORITHM; - if (BCryptEncrypt((BCRYPT_KEY_HANDLE) server_public_key, xor_str, passwd_len + 1, &padding_info, + if (BCryptEncrypt((BCRYPT_KEY_HANDLE) server_public_key, (zend_uchar *) xor_str, passwd_len + 1, &padding_info, NULL, 0, NULL, 0, &server_public_key_len, BCRYPT_PAD_OAEP)) { DBG_RETURN(0); } @@ -1071,7 +1071,7 @@ mysqlnd_caching_sha2_public_encrypt(MYSQLND_CONN_DATA * conn, mysqlnd_rsa_t serv } *crypted = emalloc(server_public_key_len); - if (BCryptEncrypt((BCRYPT_KEY_HANDLE) server_public_key, xor_str, passwd_len + 1, &padding_info, + if (BCryptEncrypt((BCRYPT_KEY_HANDLE) server_public_key, (zend_uchar *) xor_str, passwd_len + 1, &padding_info, NULL, 0, *crypted, server_public_key_len, &server_public_key_len, BCRYPT_PAD_OAEP)) { BCryptDestroyKey((BCRYPT_KEY_HANDLE) server_public_key); DBG_RETURN(0); diff --git a/ext/mysqlnd/mysqlnd_connection.c b/ext/mysqlnd/mysqlnd_connection.c index 8582e376e92a6..2787b32931747 100644 --- a/ext/mysqlnd/mysqlnd_connection.c +++ b/ext/mysqlnd/mysqlnd_connection.c @@ -2241,7 +2241,7 @@ mysqlnd_poll(MYSQLND **r_array, MYSQLND **e_array, MYSQLND ***dont_poll, long se retval = php_select(max_fd + 1, &rfds, &wfds, &efds, tv_p); if (retval == -1) { - php_error_docref(NULL, E_WARNING, "Unable to select [%d]: %s (max_fd=%d)", + php_error_docref(NULL, E_WARNING, "Unable to select [%d]: %s (max_fd=" PHP_SOCKET_FMT ")", errno, strerror(errno), max_fd); DBG_RETURN(FAIL); } diff --git a/ext/openssl/xp_ssl.c b/ext/openssl/xp_ssl.c index eb7ab93815a9c..484abf483539d 100644 --- a/ext/openssl/xp_ssl.c +++ b/ext/openssl/xp_ssl.c @@ -700,7 +700,7 @@ static int php_openssl_win_cert_verify_callback(X509_STORE_CTX *x509_store_ctx, err_code = e; } - php_error_docref(NULL, E_WARNING, "Error encoding X509 certificate: %d: %s", err_code, ERR_error_string(err_code, err_buf)); + php_error_docref(NULL, E_WARNING, "Error encoding X509 certificate: %lu: %s", err_code, ERR_error_string(err_code, err_buf)); RETURN_CERT_VERIFY_FAILURE(SSL_R_CERTIFICATE_VERIFY_FAILED); } diff --git a/ext/standard/streamsfuncs.c b/ext/standard/streamsfuncs.c index 1929075b60b71..4f9a7106c01c1 100644 --- a/ext/standard/streamsfuncs.c +++ b/ext/standard/streamsfuncs.c @@ -859,7 +859,7 @@ PHP_FUNCTION(stream_select) retval = php_select(max_fd+1, &rfds, &wfds, &efds, tv_p); if (retval == -1) { - php_error_docref(NULL, E_WARNING, "Unable to select [%d]: %s (max_fd=%d)", + php_error_docref(NULL, E_WARNING, "Unable to select [%d]: %s (max_fd=" PHP_SOCKET_FMT ")", errno, strerror(errno), max_fd); RETURN_FALSE; } diff --git a/main/php_network.h b/main/php_network.h index 0a0da4cf7084a..94a2508c89e52 100644 --- a/main/php_network.h +++ b/main/php_network.h @@ -96,8 +96,10 @@ END_EXTERN_C() #ifdef PHP_WIN32 typedef SOCKET php_socket_t; +#define PHP_SOCKET_FMT "%" PRIxPTR #else typedef int php_socket_t; +#define PHP_SOCKET_FMT "%d" #endif #ifdef PHP_WIN32 diff --git a/main/streams/plain_wrapper.c b/main/streams/plain_wrapper.c index f0e03a9343128..1fa543fc9755f 100644 --- a/main/streams/plain_wrapper.c +++ b/main/streams/plain_wrapper.c @@ -622,7 +622,7 @@ static int php_stdiop_cast(php_stream *stream, int castas, void **ret) } *(FILE**)ret = data->file; - data->fd = SOCK_ERR; + data->fd = (int) SOCK_ERR; } return SUCCESS; diff --git a/win32/registry.c b/win32/registry.c index cd9fc38c199fe..81378b0f46a5e 100644 --- a/win32/registry.c +++ b/win32/registry.c @@ -94,7 +94,7 @@ static int LoadDirectory(HashTable *directories, HKEY key, char *path, int path_ memset(name, '\0', max_name+1); memset(value, '\0', max_value+1); - if (RegEnumValue(key, i, name, &name_len, NULL, &type, value, &value_len) == ERROR_SUCCESS) { + if (RegEnumValue(key, i, name, &name_len, NULL, &type, (LPBYTE) value, &value_len) == ERROR_SUCCESS) { if ((type == REG_SZ) || (type == REG_EXPAND_SZ)) { zval data; @@ -287,7 +287,7 @@ char *GetIniPathFromRegistry() if (OpenPhpRegistryKey(NULL, &hKey)) { DWORD buflen = MAXPATHLEN; reg_location = emalloc(MAXPATHLEN+1); - if(RegQueryValueEx(hKey, PHPRC_REGISTRY_NAME, 0, NULL, reg_location, &buflen) != ERROR_SUCCESS) { + if(RegQueryValueEx(hKey, PHPRC_REGISTRY_NAME, 0, NULL, (LPBYTE) reg_location, &buflen) != ERROR_SUCCESS) { RegCloseKey(hKey); efree(reg_location); reg_location = NULL; diff --git a/win32/wsyslog.c b/win32/wsyslog.c index b4e58b15629a7..0cf3c263bc3a0 100644 --- a/win32/wsyslog.c +++ b/win32/wsyslog.c @@ -89,7 +89,7 @@ void syslog(int priority, const char *message, ...) void vsyslog(int priority, const char *message, va_list args) { - LPTSTR strs[2]; + LPCSTR strs[2]; unsigned short etype; char *tmp = NULL; DWORD evid; @@ -120,7 +120,7 @@ void vsyslog(int priority, const char *message, va_list args) /* report the event */ if (strsw[0] && strsw[1]) { - ReportEventW(PW32G(log_source), etype, (unsigned short) priority, evid, NULL, 2, 0, strsw, NULL); + ReportEventW(PW32G(log_source), etype, (unsigned short) priority, evid, NULL, 2, 0, (LPCWSTR *) strsw, NULL); free(strsw[0]); free(strsw[1]); efree(tmp); From 3a11e29706f819126645671f0204cf9527dee940 Mon Sep 17 00:00:00 2001 From: "Christoph M. Becker" Date: Sat, 18 Jan 2025 13:24:05 +0100 Subject: [PATCH 2/5] fix --- ext/ffi/ffi.c | 1 + 1 file changed, 1 insertion(+) diff --git a/ext/ffi/ffi.c b/ext/ffi/ffi.c index cac7b1b54b7c6..38261ad6420fb 100644 --- a/ext/ffi/ffi.c +++ b/ext/ffi/ffi.c @@ -904,6 +904,7 @@ static zend_always_inline zend_string *zend_ffi_mangled_func_name(zend_string *n return zend_string_copy(name); } #endif + return zend_string_copy(name); } /* }}} */ From d702114a9e03d2bbb272b3a4b56bf2a6d5de7d51 Mon Sep 17 00:00:00 2001 From: "Christoph M. Becker" Date: Sun, 19 Jan 2025 12:47:45 +0100 Subject: [PATCH 3/5] break instead of duplicating zend_string_copy() call --- ext/ffi/ffi.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ext/ffi/ffi.c b/ext/ffi/ffi.c index 38261ad6420fb..3fc97577abdea 100644 --- a/ext/ffi/ffi.c +++ b/ext/ffi/ffi.c @@ -901,7 +901,8 @@ static zend_always_inline zend_string *zend_ffi_mangled_func_name(zend_string *n return strpprintf(0, "%s@@%zu", ZSTR_VAL(name), zend_ffi_arg_size(type)); # endif default: - return zend_string_copy(name); + /* other calling conventions don't apply name mangling */ + break; } #endif return zend_string_copy(name); From d4e60f6721eb1d53906c341a472ca4b4239a856b Mon Sep 17 00:00:00 2001 From: "Christoph M. Becker" Date: Sun, 19 Jan 2025 12:49:14 +0100 Subject: [PATCH 4/5] Drop doubtful fixes --- ext/com_dotnet/com_wrapper.c | 2 +- main/streams/plain_wrapper.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ext/com_dotnet/com_wrapper.c b/ext/com_dotnet/com_wrapper.c index df39239022455..6e885fa802e9f 100644 --- a/ext/com_dotnet/com_wrapper.c +++ b/ext/com_dotnet/com_wrapper.c @@ -424,7 +424,7 @@ static void generate_dispids(php_dispatchex *disp) zend_string *name = NULL; zval *tmp, tmp2; int keytype; - zend_ulong pid; + zend_long pid; if (disp->dispid_to_name == NULL) { ALLOC_HASHTABLE(disp->dispid_to_name); diff --git a/main/streams/plain_wrapper.c b/main/streams/plain_wrapper.c index 1fa543fc9755f..f0e03a9343128 100644 --- a/main/streams/plain_wrapper.c +++ b/main/streams/plain_wrapper.c @@ -622,7 +622,7 @@ static int php_stdiop_cast(php_stream *stream, int castas, void **ret) } *(FILE**)ret = data->file; - data->fd = (int) SOCK_ERR; + data->fd = SOCK_ERR; } return SUCCESS; From ccc1cd48138ba51e69f11675e7ef201744600b29 Mon Sep 17 00:00:00 2001 From: "Christoph M. Becker" Date: Mon, 20 Jan 2025 15:00:21 +0100 Subject: [PATCH 5/5] Port https://github.com/libgd/libgd/commit/f1480ab14bd5e2e4b4d83d8f3e64e786aa810637 --- ext/gd/libgd/gd_interpolation.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/ext/gd/libgd/gd_interpolation.c b/ext/gd/libgd/gd_interpolation.c index 123769313e246..f8ba9087910fc 100644 --- a/ext/gd/libgd/gd_interpolation.c +++ b/ext/gd/libgd/gd_interpolation.c @@ -62,11 +62,6 @@ #include "gdhelpers.h" #include "gd_intern.h" -#if defined(_MSC_VER) && !defined(__clang__) -# pragma optimize("t", on) -# include -#endif - static gdImagePtr gdImageScaleBilinear(gdImagePtr im, const unsigned int new_width, const unsigned int new_height);