Skip to content

Commit 5a04796

Browse files
committed
Fix MSVC level 1 (severe) warnings
We fix (hopefully) all instances of: * <https://docs.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-1-c4005> * <https://docs.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-1-c4024> * <https://docs.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-1-c4028> * <https://docs.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-1-c4047> * <https://docs.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-1-c4087> * <https://docs.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-1-c4090> * <https://docs.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-1-c4273> * <https://docs.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-1-c4312> `zend_llist_add_element()` and `zend_llist_prepend_element()` now explicitly expect a *const* pointer. We use the macro `ZEND_VOIDP()` instead of a `(void*)` cast to suppress C4090; this should prevent accidential removal of the cast by clarifying the intention, and makes it easier to remove the casts if the issue[1] will be resolved sometime. [1] <https://developercommunity.visualstudio.com/content/problem/390711/c-compiler-incorrect-propagation-of-const-qualifie.html>
1 parent 536c02b commit 5a04796

27 files changed

+91
-47
lines changed

TSRM/tsrm_win32.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ TSRM_API void tsrm_win32_shutdown(void)
103103
#endif
104104
}/*}}}*/
105105

106-
char * tsrm_win32_get_path_sid_key(const char *pathname, size_t pathname_len, size_t *key_len)
106+
const char * tsrm_win32_get_path_sid_key(const char *pathname, size_t pathname_len, size_t *key_len)
107107
{/*{{{*/
108108
PSID pSid = TWG(impersonation_token_sid);
109109
char *ptcSid = NULL;

TSRM/tsrm_win32.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ TSRMLS_CACHE_EXTERN()
8989
#define SHM_RND FILE_MAP_WRITE
9090
#define SHM_REMAP FILE_MAP_COPY
9191

92-
char * tsrm_win32_get_path_sid_key(const char *pathname, size_t pathname_len, size_t *key_len);
92+
const char * tsrm_win32_get_path_sid_key(const char *pathname, size_t pathname_len, size_t *key_len);
9393

9494
TSRM_API void tsrm_win32_startup(void);
9595
TSRM_API void tsrm_win32_shutdown(void);

Zend/zend_llist.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ ZEND_API void zend_llist_init(zend_llist *l, size_t size, llist_dtor_func_t dtor
3131
l->persistent = persistent;
3232
}
3333

34-
ZEND_API void zend_llist_add_element(zend_llist *l, void *element)
34+
ZEND_API void zend_llist_add_element(zend_llist *l, const void *element)
3535
{
3636
zend_llist_element *tmp = pemalloc(sizeof(zend_llist_element)+l->size-1, l->persistent);
3737

@@ -49,7 +49,7 @@ ZEND_API void zend_llist_add_element(zend_llist *l, void *element)
4949
}
5050

5151

52-
ZEND_API void zend_llist_prepend_element(zend_llist *l, void *element)
52+
ZEND_API void zend_llist_prepend_element(zend_llist *l, const void *element)
5353
{
5454
zend_llist_element *tmp = pemalloc(sizeof(zend_llist_element)+l->size-1, l->persistent);
5555

Zend/zend_llist.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ typedef zend_llist_element* zend_llist_position;
4646

4747
BEGIN_EXTERN_C()
4848
ZEND_API void zend_llist_init(zend_llist *l, size_t size, llist_dtor_func_t dtor, unsigned char persistent);
49-
ZEND_API void zend_llist_add_element(zend_llist *l, void *element);
50-
ZEND_API void zend_llist_prepend_element(zend_llist *l, void *element);
49+
ZEND_API void zend_llist_add_element(zend_llist *l, const void *element);
50+
ZEND_API void zend_llist_prepend_element(zend_llist *l, const void *element);
5151
ZEND_API void zend_llist_del_element(zend_llist *l, void *element, int (*compare)(void *element1, void *element2));
5252
ZEND_API void zend_llist_destroy(zend_llist *l);
5353
ZEND_API void zend_llist_clean(zend_llist *l);

Zend/zend_portability.h

+7
Original file line numberDiff line numberDiff line change
@@ -621,4 +621,11 @@ extern "C++" {
621621
# define ZEND_IGNORE_LEAKS_END()
622622
#endif
623623

624+
/* MSVC yields C4090 when a (const T **) is passed to a (void *); ZEND_VOIDP works around that */
625+
#ifdef _MSC_VER
626+
# define ZEND_VOIDP(ptr) ((void *) ptr)
627+
#else
628+
# define ZEND_VOIDP(ptr) (ptr)
629+
#endif
630+
624631
#endif /* ZEND_PORTABILITY_H */

Zend/zend_virtual_cwd.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -303,8 +303,8 @@ static inline zend_ulong realpath_cache_key(const char *path, size_t path_len) /
303303
{
304304
register zend_ulong h;
305305
size_t bucket_key_len;
306-
char *bucket_key_start = tsrm_win32_get_path_sid_key(path, path_len, &bucket_key_len);
307-
char *bucket_key = (char *)bucket_key_start;
306+
const char *bucket_key_start = tsrm_win32_get_path_sid_key(path, path_len, &bucket_key_len);
307+
const char *bucket_key = bucket_key_start;
308308
const char *e;
309309

310310
if (!bucket_key) {

ext/com_dotnet/com_handlers.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ static void com_write_dimension(zend_object *object, zval *offset, zval *value)
177177
}
178178
}
179179

180-
static zval *com_get_property_ptr_ptr(zval *object, zval *member, int type, void **cache_slot)
180+
static zval *com_get_property_ptr_ptr(zend_object *object, zend_string *member, int type, void **cache_slot)
181181
{
182182
return NULL;
183183
}
@@ -224,10 +224,10 @@ static HashTable *com_properties_get(zend_object *object)
224224
* infinite recursion when the hash is displayed via var_dump().
225225
* Perhaps it is best to leave it un-implemented.
226226
*/
227-
return &zend_empty_array;
227+
return (HashTable *) &zend_empty_array;
228228
}
229229

230-
static HashTable *com_get_gc(zval *object, zval **table, int *n)
230+
static HashTable *com_get_gc(zend_object *object, zval **table, int *n)
231231
{
232232
*table = NULL;
233233
*n = 0;

ext/mbstring/mbstring.c

+20-20
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ static int php_mb_parse_encoding_list(const char *value, size_t value_length,
365365
zend_argument_value_error(arg_num, "contains invalid encoding \"%s\"", p1);
366366
}
367367
efree(tmpstr);
368-
pefree(list, persistent);
368+
pefree(ZEND_VOIDP(list), persistent);
369369
return FAILURE;
370370
}
371371

@@ -400,7 +400,7 @@ static int php_mb_parse_encoding_array(HashTable *target_hash, const mbfl_encodi
400400
ZEND_HASH_FOREACH_VAL(target_hash, hash_entry) {
401401
zend_string *encoding_str = zval_try_get_string(hash_entry);
402402
if (UNEXPECTED(!encoding_str)) {
403-
efree(list);
403+
efree(ZEND_VOIDP(list));
404404
return FAILURE;
405405
}
406406

@@ -424,7 +424,7 @@ static int php_mb_parse_encoding_array(HashTable *target_hash, const mbfl_encodi
424424
} else {
425425
zend_argument_value_error(arg_num, "contains invalid encoding \"%s\"", ZSTR_VAL(encoding_str));
426426
zend_string_release(encoding_str);
427-
efree(list);
427+
efree(ZEND_VOIDP(list));
428428
return FAILURE;
429429
}
430430
}
@@ -809,7 +809,7 @@ static PHP_INI_MH(OnUpdate_mbstring_detect_order)
809809

810810
if (!new_value) {
811811
if (MBSTRG(detect_order_list)) {
812-
pefree(MBSTRG(detect_order_list), 1);
812+
pefree(ZEND_VOIDP(MBSTRG(detect_order_list)), 1);
813813
}
814814
MBSTRG(detect_order_list) = NULL;
815815
MBSTRG(detect_order_list_size) = 0;
@@ -821,7 +821,7 @@ static PHP_INI_MH(OnUpdate_mbstring_detect_order)
821821
}
822822

823823
if (MBSTRG(detect_order_list)) {
824-
pefree(MBSTRG(detect_order_list), 1);
824+
pefree(ZEND_VOIDP(MBSTRG(detect_order_list)), 1);
825825
}
826826
MBSTRG(detect_order_list) = list;
827827
MBSTRG(detect_order_list_size) = size;
@@ -836,7 +836,7 @@ static int _php_mb_ini_mbstring_http_input_set(const char *new_value, size_t new
836836
return FAILURE;
837837
}
838838
if (MBSTRG(http_input_list)) {
839-
pefree(MBSTRG(http_input_list), 1);
839+
pefree(ZEND_VOIDP(MBSTRG(http_input_list)), 1);
840840
}
841841
MBSTRG(http_input_list) = list;
842842
MBSTRG(http_input_list_size) = size;
@@ -1128,10 +1128,10 @@ ZEND_TSRMLS_CACHE_UPDATE();
11281128
static PHP_GSHUTDOWN_FUNCTION(mbstring)
11291129
{
11301130
if (mbstring_globals->http_input_list) {
1131-
free(mbstring_globals->http_input_list);
1131+
free(ZEND_VOIDP(mbstring_globals->http_input_list));
11321132
}
11331133
if (mbstring_globals->detect_order_list) {
1134-
free(mbstring_globals->detect_order_list);
1134+
free(ZEND_VOIDP(mbstring_globals->detect_order_list));
11351135
}
11361136
if (mbstring_globals->http_output_conv_mimetypes) {
11371137
_php_mb_free_regex(mbstring_globals->http_output_conv_mimetypes);
@@ -1236,7 +1236,7 @@ PHP_RINIT_FUNCTION(mbstring)
12361236
PHP_RSHUTDOWN_FUNCTION(mbstring)
12371237
{
12381238
if (MBSTRG(current_detect_order_list) != NULL) {
1239-
efree(MBSTRG(current_detect_order_list));
1239+
efree(ZEND_VOIDP(MBSTRG(current_detect_order_list)));
12401240
MBSTRG(current_detect_order_list) = NULL;
12411241
MBSTRG(current_detect_order_list_size) = 0;
12421242
}
@@ -1510,13 +1510,13 @@ PHP_FUNCTION(mb_detect_order)
15101510
}
15111511

15121512
if (size == 0) {
1513-
efree(list);
1513+
efree(ZEND_VOIDP(list));
15141514
zend_argument_value_error(1, "must specify at least one encoding");
15151515
RETURN_THROWS();
15161516
}
15171517

15181518
if (MBSTRG(current_detect_order_list)) {
1519-
efree(MBSTRG(current_detect_order_list));
1519+
efree(ZEND_VOIDP(MBSTRG(current_detect_order_list)));
15201520
}
15211521
MBSTRG(current_detect_order_list) = list;
15221522
MBSTRG(current_detect_order_list_size) = size;
@@ -2632,7 +2632,7 @@ PHP_FUNCTION(mb_convert_encoding)
26322632
}
26332633

26342634
if (!num_from_encodings) {
2635-
efree(from_encodings);
2635+
efree(ZEND_VOIDP(from_encodings));
26362636
zend_argument_value_error(3, "must specify at least one encoding");
26372637
RETURN_THROWS();
26382638
}
@@ -2658,7 +2658,7 @@ PHP_FUNCTION(mb_convert_encoding)
26582658
}
26592659

26602660
if (free_from_encodings) {
2661-
efree(from_encodings);
2661+
efree(ZEND_VOIDP(from_encodings));
26622662
}
26632663
}
26642664
/* }}} */
@@ -2811,7 +2811,7 @@ PHP_FUNCTION(mb_detect_encoding)
28112811
}
28122812

28132813
if (size == 0) {
2814-
efree(elist);
2814+
efree(ZEND_VOIDP(elist));
28152815
zend_argument_value_error(2, "must specify at least one encoding");
28162816
RETURN_THROWS();
28172817
}
@@ -2826,7 +2826,7 @@ PHP_FUNCTION(mb_detect_encoding)
28262826
ret = mbfl_identify_encoding(&string, elist, size, strict);
28272827

28282828
if (free_elist) {
2829-
efree(elist);
2829+
efree(ZEND_VOIDP(elist));
28302830
}
28312831

28322832
if (ret == NULL) {
@@ -3191,7 +3191,7 @@ PHP_FUNCTION(mb_convert_variables)
31913191
}
31923192

31933193
if (elistsz == 0) {
3194-
efree(elist);
3194+
efree(ZEND_VOIDP(elist));
31953195
zend_argument_value_error(2, "must specify at least one encoding");
31963196
RETURN_THROWS();
31973197
}
@@ -3213,20 +3213,20 @@ PHP_FUNCTION(mb_convert_variables)
32133213
from_encoding = mbfl_encoding_detector_judge(identd);
32143214
mbfl_encoding_detector_delete(identd);
32153215
if (recursion_error) {
3216-
efree(elist);
3216+
efree(ZEND_VOIDP(elist));
32173217
php_error_docref(NULL, E_WARNING, "Cannot handle recursive references");
32183218
RETURN_FALSE;
32193219
}
32203220
}
32213221

32223222
if (!from_encoding) {
32233223
php_error_docref(NULL, E_WARNING, "Unable to detect encoding");
3224-
efree(elist);
3224+
efree(ZEND_VOIDP(elist));
32253225
RETURN_FALSE;
32263226
}
32273227
}
32283228

3229-
efree(elist);
3229+
efree(ZEND_VOIDP(elist));
32303230

32313231
convd = mbfl_buffer_converter_new(from_encoding, to_encoding, 0);
32323232
/* If this assertion fails this means some memory allocation failure which is a bug */
@@ -4338,7 +4338,7 @@ static void php_mb_populate_current_detect_order_list(void)
43384338
if (MBSTRG(detect_order_list) && MBSTRG(detect_order_list_size)) {
43394339
nentries = MBSTRG(detect_order_list_size);
43404340
entry = (const mbfl_encoding **)safe_emalloc(nentries, sizeof(mbfl_encoding*), 0);
4341-
memcpy(entry, MBSTRG(detect_order_list), sizeof(mbfl_encoding*) * nentries);
4341+
memcpy(ZEND_VOIDP(entry), MBSTRG(detect_order_list), sizeof(mbfl_encoding*) * nentries);
43424342
} else {
43434343
const enum mbfl_no_encoding *src = MBSTRG(default_detect_order_list);
43444344
size_t i;

ext/mysqlnd/mysqlnd_auth.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -752,7 +752,7 @@ static mysqlnd_rsa_t
752752
mysqlnd_sha256_get_rsa_from_pem(const char *buf, size_t len)
753753
{
754754
BCRYPT_KEY_HANDLE ret = 0;
755-
LPCSTR der_buf = NULL;
755+
LPSTR der_buf = NULL;
756756
DWORD der_len;
757757
CERT_PUBLIC_KEY_INFO *key_info = NULL;
758758
DWORD key_info_len;

ext/opcache/jit/zend_jit_trace.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -1961,7 +1961,7 @@ static zend_lifetime_interval** zend_jit_trace_allocate_registers(zend_jit_trace
19611961

19621962
memset(start, -1, sizeof(int) * ssa->vars_count * 2);
19631963
memset(flags, 0, sizeof(uint8_t) * ssa->vars_count);
1964-
memset(vars_op_array, 0, sizeof(zend_op_array*) * ssa->vars_count);
1964+
memset(ZEND_VOIDP(vars_op_array), 0, sizeof(zend_op_array*) * ssa->vars_count);
19651965

19661966
op_array = trace_buffer->op_array;
19671967
jit_extension =
@@ -5353,7 +5353,7 @@ static int zend_jit_setup_hot_trace_counters(zend_op_array *op_array)
53535353

53545354
static void zend_jit_trace_init_caches(void)
53555355
{
5356-
memset(JIT_G(bad_root_cache_opline), 0, sizeof(JIT_G(bad_root_cache_opline)));
5356+
memset(ZEND_VOIDP(JIT_G(bad_root_cache_opline)), 0, sizeof(JIT_G(bad_root_cache_opline)));
53575357
memset(JIT_G(bad_root_cache_count), 0, sizeof(JIT_G(bad_root_cache_count)));
53585358
memset(JIT_G(bad_root_cache_stop), 0, sizeof(JIT_G(bad_root_cache_count)));
53595359
JIT_G(bad_root_slot) = 0;

ext/opcache/jit/zend_jit_vm_helpers.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL zend_jit_profile_helper(ZEND_OPCODE_HANDLE
183183
{
184184
zend_op_array *op_array = (zend_op_array*)EX(func);
185185
zend_jit_op_array_extension *jit_extension = (zend_jit_op_array_extension*)ZEND_FUNC_INFO(op_array);
186-
zend_vm_opcode_handler_t handler = jit_extension->orig_handler;
186+
zend_vm_opcode_handler_t handler = (zend_vm_opcode_handler_t) jit_extension->orig_handler;
187187
++*(uintptr_t*)(EX(run_time_cache) + zend_jit_profile_counter_rid);
188188
++zend_jit_profile_counter;
189189
ZEND_OPCODE_TAIL_CALL(handler);

ext/opcache/jit/zend_jit_x86.dasc

+1-1
Original file line numberDiff line numberDiff line change
@@ -2607,7 +2607,7 @@ static int zend_jit_setup(void)
26072607
/* To find offset of "_tsrm_ls_cache" in TLS segment we perform a linear scan of local TLS memory */
26082608
/* Probably, it might be better solution */
26092609
do {
2610-
void ***tls_mem = ((void***)__readgsqword(0x58))[_tls_index];
2610+
void ***tls_mem = ((void**)__readgsqword(0x58))[_tls_index];
26112611
void *val = _tsrm_ls_cache;
26122612
size_t offset = 0;
26132613
size_t size = (char*)&_tls_end - (char*)&_tls_start;

ext/pdo_odbc/odbc_driver.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ static int pdo_odbc_handle_factory(pdo_dbh_t *dbh, zval *driver_options) /* {{{
420420
}
421421

422422
rc = SQLSetConnectAttr(H->dbc, SQL_ATTR_AUTOCOMMIT,
423-
(SQLPOINTER)(dbh->auto_commit ? SQL_AUTOCOMMIT_ON : SQL_AUTOCOMMIT_OFF), SQL_IS_INTEGER);
423+
(SQLPOINTER)(intptr_t)(dbh->auto_commit ? SQL_AUTOCOMMIT_ON : SQL_AUTOCOMMIT_OFF), SQL_IS_INTEGER);
424424
if (rc != SQL_SUCCESS) {
425425
pdo_odbc_drv_error("SQLSetConnectAttr AUTOCOMMIT");
426426
goto fail;

ext/session/session.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -2821,7 +2821,7 @@ static PHP_MSHUTDOWN_FUNCTION(session) /* {{{ */
28212821
}
28222822

28232823
ps_serializers[PREDEFINED_SERIALIZERS].name = NULL;
2824-
memset(&ps_modules[PREDEFINED_MODULES], 0, (MAX_MODULES-PREDEFINED_MODULES)*sizeof(ps_module *));
2824+
memset(ZEND_VOIDP(&ps_modules[PREDEFINED_MODULES]), 0, (MAX_MODULES-PREDEFINED_MODULES)*sizeof(ps_module *));
28252825

28262826
return SUCCESS;
28272827
}

ext/snmp/snmp.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1507,7 +1507,7 @@ PHP_METHOD(SNMP, __construct)
15071507
case SNMP_VERSION_3:
15081508
break;
15091509
default:
1510-
zend_argument_value_error(zend_ce_exception, 1, "must be a valid SNMP protocol version");
1510+
zend_argument_value_error(1, "must be a valid SNMP protocol version");
15111511
RETURN_THROWS();
15121512
}
15131513

ext/standard/proc_open.c

+2
Original file line numberDiff line numberDiff line change
@@ -841,6 +841,7 @@ static int set_proc_descriptor_from_resource(zval *resource, descriptorspec_item
841841
return SUCCESS;
842842
}
843843

844+
#ifndef PHP_WIN32
844845
static int close_parentends_of_pipes(descriptorspec_item *descriptors, int ndesc)
845846
{
846847
/* We are running in child process
@@ -863,6 +864,7 @@ static int close_parentends_of_pipes(descriptorspec_item *descriptors, int ndesc
863864

864865
return SUCCESS;
865866
}
867+
#endif
866868

867869
static void close_all_descriptors(descriptorspec_item *descriptors, int ndesc)
868870
{

ext/standard/string.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1109,7 +1109,7 @@ PHPAPI void php_explode_negative_limit(const zend_string *delim, zend_string *st
11091109
do {
11101110
if (found >= allocated) {
11111111
allocated = found + EXPLODE_ALLOC_STEP;/* make sure we have enough memory */
1112-
positions = erealloc(positions, allocated*sizeof(char *));
1112+
positions = erealloc(ZEND_VOIDP(positions), allocated*sizeof(char *));
11131113
}
11141114
positions[found++] = p1 = p2 + ZSTR_LEN(delim);
11151115
p2 = php_memnstr(p1, ZSTR_VAL(delim), ZSTR_LEN(delim), endp);

ext/zend_test/config.w32

+1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ ARG_ENABLE("zend-test", "enable zend-test extension", "no");
44

55
if (PHP_ZEND_TEST != "no") {
66
EXTENSION("zend_test", "test.c", PHP_ZEND_TEST_SHARED, "/DZEND_ENABLE_STATIC_TSRMLS_CACHE=1");
7+
ADD_FLAG("CFLAGS_ZEND_TEST", "/D PHP_ZEND_TEST_EXPORTS ");
78
}

ext/zend_test/php_test.h

+12-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,17 @@ struct bug79096 {
3535
uint64_t b;
3636
};
3737

38-
ZEND_API struct bug79096 bug79096(void);
39-
ZEND_API void bug79532(off_t *array, size_t elems);
38+
#ifdef PHP_WIN32
39+
# ifdef PHP_ZEND_TEST_EXPORTS
40+
# define PHP_ZEND_TEST_API __declspec(dllexport)
41+
# else
42+
# define PHP_ZEND_TEST_API __declspec(dllimport)
43+
# endif
44+
#else
45+
# define PHP_ZEND_TEST_API ZEND_API
46+
#endif
47+
48+
PHP_ZEND_TEST_API struct bug79096 bug79096(void);
49+
PHP_ZEND_TEST_API void bug79532(off_t *array, size_t elems);
4050

4151
#endif

0 commit comments

Comments
 (0)