Skip to content

Commit a15ba76

Browse files
authored
zend_ini: Make ZEND_INI_GET_ADDR() return a void* pointer (#21119)
* zend_ini: Make `ZEND_INI_GET_ADDR()` return a `void*` pointer Since the actual type of the storage location is not known, a `void*` is more appropriate and avoids explicit casts that are no more safe than the implicit cast from `void*`. * tree-wide: Remove explicit casts of `ZEND_INI_GET_ADDR()` * UPGRADING.INTERNALS
1 parent 27d28ee commit a15ba76

File tree

14 files changed

+42
-39
lines changed

14 files changed

+42
-39
lines changed

UPGRADING.INTERNALS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ PHP 8.6 INTERNALS UPGRADE NOTES
6464
zend_enum_RoundingMode parameter.
6565
. Added Z_PARAM_ENUM().
6666
. Added zend_enum_fetch_case_id().
67+
. ZEND_INI_GET_ADDR() is now a void* pointer instead of a char* pointer. This
68+
more correctly represents the generic nature of the returned pointer and
69+
allows to remove explicit casts, but possibly breaks pointer arithmetic
70+
performed on the result.
6771

6872
========================
6973
2. Build system changes

Zend/zend.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ static ZEND_INI_MH(OnUpdateScriptEncoding) /* {{{ */
157157

158158
static ZEND_INI_MH(OnUpdateAssertions) /* {{{ */
159159
{
160-
zend_long *p = (zend_long *) ZEND_INI_GET_ADDR();
160+
zend_long *p = ZEND_INI_GET_ADDR();
161161

162162
zend_long val = zend_ini_parse_quantity_warn(new_value, entry->name);
163163

Zend/zend_ini.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -963,15 +963,15 @@ ZEND_INI_DISP(display_link_numbers) /* {{{ */
963963
/* Standard message handlers */
964964
ZEND_API ZEND_INI_MH(OnUpdateBool) /* {{{ */
965965
{
966-
bool *p = (bool *) ZEND_INI_GET_ADDR();
966+
bool *p = ZEND_INI_GET_ADDR();
967967
*p = zend_ini_parse_bool(new_value);
968968
return SUCCESS;
969969
}
970970
/* }}} */
971971

972972
ZEND_API ZEND_INI_MH(OnUpdateLong) /* {{{ */
973973
{
974-
zend_long *p = (zend_long *) ZEND_INI_GET_ADDR();
974+
zend_long *p = ZEND_INI_GET_ADDR();
975975
*p = zend_ini_parse_quantity_warn(new_value, entry->name);
976976
return SUCCESS;
977977
}
@@ -984,7 +984,7 @@ ZEND_API ZEND_INI_MH(OnUpdateLongGEZero) /* {{{ */
984984
return FAILURE;
985985
}
986986

987-
zend_long *p = (zend_long *) ZEND_INI_GET_ADDR();
987+
zend_long *p = ZEND_INI_GET_ADDR();
988988
*p = tmp;
989989

990990
return SUCCESS;
@@ -993,15 +993,15 @@ ZEND_API ZEND_INI_MH(OnUpdateLongGEZero) /* {{{ */
993993

994994
ZEND_API ZEND_INI_MH(OnUpdateReal) /* {{{ */
995995
{
996-
double *p = (double *) ZEND_INI_GET_ADDR();
996+
double *p = ZEND_INI_GET_ADDR();
997997
*p = zend_strtod(ZSTR_VAL(new_value), NULL);
998998
return SUCCESS;
999999
}
10001000
/* }}} */
10011001

10021002
ZEND_API ZEND_INI_MH(OnUpdateString) /* {{{ */
10031003
{
1004-
char **p = (char **) ZEND_INI_GET_ADDR();
1004+
char **p = ZEND_INI_GET_ADDR();
10051005
*p = new_value ? ZSTR_VAL(new_value) : NULL;
10061006
return SUCCESS;
10071007
}
@@ -1013,15 +1013,15 @@ ZEND_API ZEND_INI_MH(OnUpdateStringUnempty) /* {{{ */
10131013
return FAILURE;
10141014
}
10151015

1016-
char **p = (char **) ZEND_INI_GET_ADDR();
1016+
char **p = ZEND_INI_GET_ADDR();
10171017
*p = new_value ? ZSTR_VAL(new_value) : NULL;
10181018
return SUCCESS;
10191019
}
10201020
/* }}} */
10211021

10221022
ZEND_API ZEND_INI_MH(OnUpdateStr) /* {{{ */
10231023
{
1024-
zend_string **p = (zend_string **) ZEND_INI_GET_ADDR();
1024+
zend_string **p = ZEND_INI_GET_ADDR();
10251025
*p = new_value;
10261026
return SUCCESS;
10271027
}
@@ -1033,7 +1033,7 @@ ZEND_API ZEND_INI_MH(OnUpdateStrNotEmpty) /* {{{ */
10331033
return FAILURE;
10341034
}
10351035

1036-
zend_string **p = (zend_string **) ZEND_INI_GET_ADDR();
1036+
zend_string **p = ZEND_INI_GET_ADDR();
10371037
*p = new_value;
10381038
return SUCCESS;
10391039
}

Zend/zend_ini.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,6 @@ typedef struct _zend_ini_parser_param {
257257
# define ZEND_INI_GET_BASE() ((char *) ts_resource(*((int *) mh_arg2)))
258258
#endif
259259

260-
#define ZEND_INI_GET_ADDR() (ZEND_INI_GET_BASE() + (size_t) mh_arg1)
260+
#define ZEND_INI_GET_ADDR() ((void*)(ZEND_INI_GET_BASE() + (size_t) mh_arg1))
261261

262262
#endif /* ZEND_INI_H */

ext/bcmath/bcmath.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,14 @@ ZEND_GET_MODULE(bcmath)
7474

7575
ZEND_INI_MH(OnUpdateScale)
7676
{
77-
int *p;
77+
int *p = ZEND_INI_GET_ADDR();
7878
zend_long tmp;
7979

8080
tmp = zend_ini_parse_quantity_warn(new_value, entry->name);
8181
if (tmp < 0 || tmp > INT_MAX) {
8282
return FAILURE;
8383
}
8484

85-
p = (int *) ZEND_INI_GET_ADDR();
8685
*p = (int) tmp;
8786

8887
return SUCCESS;

ext/intl/php_intl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ char* canonicalize_locale_string(const char* locale) {
115115

116116
static PHP_INI_MH(OnUpdateErrorLevel)
117117
{
118-
zend_long *p = (zend_long *) ZEND_INI_GET_ADDR();
118+
zend_long *p = ZEND_INI_GET_ADDR();
119119
*p = zend_ini_parse_quantity_warn(new_value, entry->name);
120120
if (*p) {
121121
php_error_docref("session.configuration", E_DEPRECATED,

ext/opcache/zend_accelerator_module.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ static ZEND_INI_MH(OnUpdateMemoryConsumption)
8787
return FAILURE;
8888
}
8989

90-
zend_long *p = (zend_long *) ZEND_INI_GET_ADDR();
90+
zend_long *p = ZEND_INI_GET_ADDR();
9191
zend_long memsize = atoi(ZSTR_VAL(new_value));
9292
/* sanity check we must use at least 8 MB */
9393
if (memsize < 8) {
@@ -104,7 +104,7 @@ static ZEND_INI_MH(OnUpdateMemoryConsumption)
104104

105105
static ZEND_INI_MH(OnUpdateInternedStringsBuffer)
106106
{
107-
zend_long *p = (zend_long *) ZEND_INI_GET_ADDR();
107+
zend_long *p = ZEND_INI_GET_ADDR();
108108
zend_long size = zend_ini_parse_quantity_warn(new_value, entry->name);
109109

110110
if (size < 0) {
@@ -123,7 +123,7 @@ static ZEND_INI_MH(OnUpdateInternedStringsBuffer)
123123

124124
static ZEND_INI_MH(OnUpdateMaxAcceleratedFiles)
125125
{
126-
zend_long *p = (zend_long *) ZEND_INI_GET_ADDR();
126+
zend_long *p = ZEND_INI_GET_ADDR();
127127
zend_long size = atoi(ZSTR_VAL(new_value));
128128
/* sanity check we must use a value between MIN_ACCEL_FILES and MAX_ACCEL_FILES */
129129
if (size < MIN_ACCEL_FILES) {
@@ -140,7 +140,7 @@ static ZEND_INI_MH(OnUpdateMaxAcceleratedFiles)
140140

141141
static ZEND_INI_MH(OnUpdateMaxWastedPercentage)
142142
{
143-
double *p = (double *) ZEND_INI_GET_ADDR();
143+
double *p = ZEND_INI_GET_ADDR();
144144
zend_long percentage = atoi(ZSTR_VAL(new_value));
145145

146146
if (percentage <= 0 || percentage > 50) {
@@ -159,7 +159,7 @@ static ZEND_INI_MH(OnEnable)
159159
return OnUpdateBool(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage);
160160
} else {
161161
/* It may be only temporarily disabled */
162-
bool *p = (bool *) ZEND_INI_GET_ADDR();
162+
bool *p = ZEND_INI_GET_ADDR();
163163
if (zend_ini_parse_bool(new_value)) {
164164
if (*p) {
165165
/* Do not warn if OPcache is enabled, as the update would be a noop anyways. */
@@ -206,7 +206,7 @@ static ZEND_INI_MH(OnUpdateJit)
206206

207207
static ZEND_INI_MH(OnUpdateJitDebug)
208208
{
209-
zend_long *p = (zend_long *) ZEND_INI_GET_ADDR();
209+
zend_long *p = ZEND_INI_GET_ADDR();
210210
zend_long val = zend_ini_parse_quantity_warn(new_value, entry->name);
211211

212212
if (zend_jit_debug_config(*p, val, stage) == SUCCESS) {
@@ -220,7 +220,7 @@ static ZEND_INI_MH(OnUpdateCounter)
220220
{
221221
zend_long val = zend_ini_parse_quantity_warn(new_value, entry->name);
222222
if (val >= 0 && val < 256) {
223-
zend_long *p = (zend_long *) ZEND_INI_GET_ADDR();
223+
zend_long *p = ZEND_INI_GET_ADDR();
224224
*p = val;
225225
return SUCCESS;
226226
}
@@ -232,7 +232,7 @@ static ZEND_INI_MH(OnUpdateUnrollC)
232232
{
233233
zend_long val = zend_ini_parse_quantity_warn(new_value, entry->name);
234234
if (val > 0 && val < ZEND_JIT_TRACE_MAX_CALL_DEPTH) {
235-
zend_long *p = (zend_long *) ZEND_INI_GET_ADDR();
235+
zend_long *p = ZEND_INI_GET_ADDR();
236236
*p = val;
237237
return SUCCESS;
238238
}
@@ -245,7 +245,7 @@ static ZEND_INI_MH(OnUpdateUnrollR)
245245
{
246246
zend_long val = zend_ini_parse_quantity_warn(new_value, entry->name);
247247
if (val >= 0 && val < ZEND_JIT_TRACE_MAX_RET_DEPTH) {
248-
zend_long *p = (zend_long *) ZEND_INI_GET_ADDR();
248+
zend_long *p = ZEND_INI_GET_ADDR();
249249
*p = val;
250250
return SUCCESS;
251251
}
@@ -258,7 +258,7 @@ static ZEND_INI_MH(OnUpdateUnrollL)
258258
{
259259
zend_long val = zend_ini_parse_quantity_warn(new_value, entry->name);
260260
if (val > 0 && val < ZEND_JIT_TRACE_MAX_LOOPS_UNROLL) {
261-
zend_long *p = (zend_long *) ZEND_INI_GET_ADDR();
261+
zend_long *p = ZEND_INI_GET_ADDR();
262262
*p = val;
263263
return SUCCESS;
264264
}
@@ -271,7 +271,7 @@ static ZEND_INI_MH(OnUpdateMaxTraceLength)
271271
{
272272
zend_long val = zend_ini_parse_quantity_warn(new_value, entry->name);
273273
if (val > 3 && val <= ZEND_JIT_TRACE_MAX_LENGTH) {
274-
zend_long *p = (zend_long *) ZEND_INI_GET_ADDR();
274+
zend_long *p = ZEND_INI_GET_ADDR();
275275
*p = val;
276276
return SUCCESS;
277277
}

ext/session/session.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -812,7 +812,7 @@ static PHP_INI_MH(OnUpdateSessionGcProbability)
812812
return FAILURE;
813813
}
814814

815-
zend_long *p = (zend_long *) ZEND_INI_GET_ADDR();
815+
zend_long *p = ZEND_INI_GET_ADDR();
816816
*p = tmp;
817817

818818
return SUCCESS;
@@ -830,7 +830,7 @@ static PHP_INI_MH(OnUpdateSessionDivisor)
830830
return FAILURE;
831831
}
832832

833-
zend_long *p = (zend_long *) ZEND_INI_GET_ADDR();
833+
zend_long *p = ZEND_INI_GET_ADDR();
834834
*p = tmp;
835835

836836
return SUCCESS;
@@ -859,7 +859,7 @@ static PHP_INI_MH(OnUpdateUseOnlyCookies)
859859
{
860860
SESSION_CHECK_ACTIVE_STATE;
861861
SESSION_CHECK_OUTPUT_STATE;
862-
bool *p = (bool *) ZEND_INI_GET_ADDR();
862+
bool *p = ZEND_INI_GET_ADDR();
863863
*p = zend_ini_parse_bool(new_value);
864864
if (!*p) {
865865
php_error_docref("session.configuration", E_DEPRECATED, "Disabling session.use_only_cookies INI setting is deprecated");
@@ -871,7 +871,7 @@ static PHP_INI_MH(OnUpdateUseTransSid)
871871
{
872872
SESSION_CHECK_ACTIVE_STATE;
873873
SESSION_CHECK_OUTPUT_STATE;
874-
bool *p = (bool *) ZEND_INI_GET_ADDR();
874+
bool *p = ZEND_INI_GET_ADDR();
875875
*p = zend_ini_parse_bool(new_value);
876876
if (*p) {
877877
php_error_docref("session.configuration", E_DEPRECATED, "Enabling session.use_trans_sid INI setting is deprecated");

ext/soap/soap.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ ZEND_GET_MODULE(soap)
349349

350350
ZEND_INI_MH(OnUpdateCacheMode)
351351
{
352-
char *p = (char *) ZEND_INI_GET_ADDR();
352+
char *p = ZEND_INI_GET_ADDR();
353353
*p = (char)atoi(ZSTR_VAL(new_value));
354354
return SUCCESS;
355355
}

ext/standard/assert.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ static PHP_INI_MH(OnChangeCallback) /* {{{ */
7979

8080
static PHP_INI_MH(OnUpdateActiveBool)
8181
{
82-
bool *p = (bool *) ZEND_INI_GET_ADDR();
82+
bool *p = ZEND_INI_GET_ADDR();
8383
*p = zend_ini_parse_bool(new_value);
8484
if (php_must_emit_ini_deprecation(stage) && !*p) {
8585
php_error_docref(NULL, E_DEPRECATED, "assert.active INI setting is deprecated");
@@ -89,7 +89,7 @@ static PHP_INI_MH(OnUpdateActiveBool)
8989

9090
static PHP_INI_MH(OnUpdateBailBool)
9191
{
92-
bool *p = (bool *) ZEND_INI_GET_ADDR();
92+
bool *p = ZEND_INI_GET_ADDR();
9393
*p = zend_ini_parse_bool(new_value);
9494
if (php_must_emit_ini_deprecation(stage) && *p) {
9595
php_error_docref(NULL, E_DEPRECATED, "assert.bail INI setting is deprecated");
@@ -99,7 +99,7 @@ static PHP_INI_MH(OnUpdateBailBool)
9999

100100
static PHP_INI_MH(OnUpdateExceptionBool)
101101
{
102-
bool *p = (bool *) ZEND_INI_GET_ADDR();
102+
bool *p = ZEND_INI_GET_ADDR();
103103
*p = zend_ini_parse_bool(new_value);
104104
if (php_must_emit_ini_deprecation(stage) && !*p) {
105105
php_error_docref(NULL, E_DEPRECATED, "assert.exception INI setting is deprecated");
@@ -110,7 +110,7 @@ static PHP_INI_MH(OnUpdateExceptionBool)
110110

111111
static PHP_INI_MH(OnUpdateWarningBool)
112112
{
113-
bool *p = (bool *) ZEND_INI_GET_ADDR();
113+
bool *p = ZEND_INI_GET_ADDR();
114114
*p = zend_ini_parse_bool(new_value);
115115
if (php_must_emit_ini_deprecation(stage) && !*p) {
116116
php_error_docref(NULL, E_DEPRECATED, "assert.warning INI setting is deprecated");

0 commit comments

Comments
 (0)