Skip to content

Commit e84bffd

Browse files
committed
Fix compile warnings under GCC 15.2.1
The compiler now infers constness through string functions. Adhere to that. It also now warns about using multiplications in conditions.
1 parent cf9d6f4 commit e84bffd

14 files changed

Lines changed: 39 additions & 38 deletions

File tree

Zend/zend_hash.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ static zend_always_inline void zend_hash_real_init_mixed_ex(HashTable *ht)
169169
void *data;
170170
uint32_t nSize = ht->nTableSize;
171171

172-
ZEND_ASSERT(HT_SIZE_TO_MASK(nSize));
172+
ZEND_ASSERT(HT_SIZE_TO_MASK(nSize) != 0);
173173

174174
if (UNEXPECTED(GC_FLAGS(ht) & IS_ARRAY_PERSISTENT)) {
175175
data = pemalloc(HT_SIZE_EX(nSize, HT_SIZE_TO_MASK(nSize)), 1);
@@ -351,7 +351,7 @@ ZEND_API void ZEND_FASTCALL zend_hash_packed_to_hash(HashTable *ht)
351351
uint32_t i;
352352
uint32_t nSize = ht->nTableSize;
353353

354-
ZEND_ASSERT(HT_SIZE_TO_MASK(nSize));
354+
ZEND_ASSERT(HT_SIZE_TO_MASK(nSize) != 0);
355355

356356
HT_ASSERT_RC1(ht);
357357
// Alloc before assign to avoid inconsistencies on OOM
@@ -399,7 +399,7 @@ ZEND_API void ZEND_FASTCALL zend_hash_extend(HashTable *ht, uint32_t nSize, bool
399399

400400
if (nSize == 0) return;
401401

402-
ZEND_ASSERT(HT_SIZE_TO_MASK(nSize));
402+
ZEND_ASSERT(HT_SIZE_TO_MASK(nSize) != 0);
403403

404404
if (UNEXPECTED(HT_FLAGS(ht) & HASH_FLAG_UNINITIALIZED)) {
405405
if (nSize > ht->nTableSize) {
@@ -1318,7 +1318,7 @@ static void ZEND_FASTCALL zend_hash_do_resize(HashTable *ht)
13181318
uint32_t nSize = ht->nTableSize + ht->nTableSize;
13191319
Bucket *old_buckets = ht->arData;
13201320

1321-
ZEND_ASSERT(HT_SIZE_TO_MASK(nSize));
1321+
ZEND_ASSERT(HT_SIZE_TO_MASK(nSize) != 0);
13221322

13231323
new_data = pemalloc(HT_SIZE_EX(nSize, HT_SIZE_TO_MASK(nSize)), GC_FLAGS(ht) & IS_ARRAY_PERSISTENT);
13241324
ht->nTableSize = nSize;

ext/filter/logical_filters.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -723,7 +723,7 @@ void php_filter_validate_email(PHP_INPUT_FILTER_PARAM_DECL) /* {{{ */
723723
}
724724
/* }}} */
725725

726-
static int _php_filter_validate_ipv4(char *str, size_t str_len, int *ip) /* {{{ */
726+
static int _php_filter_validate_ipv4(const char *str, size_t str_len, int *ip) /* {{{ */
727727
{
728728
const char *end = str + str_len;
729729
int num, m;
@@ -764,7 +764,7 @@ static int _php_filter_validate_ipv6(const char *str, size_t str_len, int ip[8])
764764
int blocks = 0;
765765
unsigned int num, n;
766766
int i;
767-
char *ipv4;
767+
const char *ipv4;
768768
const char *end;
769769
int ip4elm[4];
770770
const char *s = str;

ext/iconv/iconv.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ static zend_result php_iconv_output_handler(void **nothing, php_output_context *
320320

321321
if (mimetype != NULL && (!(output_context->op & PHP_OUTPUT_HANDLER_CLEAN) || ((output_context->op & PHP_OUTPUT_HANDLER_START) && !(output_context->op & PHP_OUTPUT_HANDLER_FINAL)))) {
322322
size_t len;
323-
char *p = strstr(get_output_encoding(), "//");
323+
const char *p = strstr(get_output_encoding(), "//");
324324

325325
if (p) {
326326
len = spprintf(&content_type, 0, "Content-Type:%.*s; charset=%.*s", mimetype_len ? mimetype_len : (int) strlen(mimetype), mimetype, (int) (p - get_output_encoding()), get_output_encoding());
@@ -2577,7 +2577,7 @@ static php_stream_filter *php_iconv_stream_filter_factory_create(const char *nam
25772577
{
25782578
php_stream_filter *retval = NULL;
25792579
php_iconv_stream_filter *inst;
2580-
char *from_charset = NULL, *to_charset = NULL;
2580+
const char *from_charset = NULL, *to_charset = NULL;
25812581
size_t from_charset_len, to_charset_len;
25822582

25832583
if ((from_charset = strchr(name, '.')) == NULL) {

ext/standard/exec.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ PHPAPI zend_string *php_escape_shell_cmd(const zend_string *unescaped_cmd)
282282
size_t x, y;
283283
zend_string *cmd;
284284
#ifndef PHP_WIN32
285-
char *p = NULL;
285+
const char *p = NULL;
286286
#endif
287287

288288
ZEND_ASSERT(ZSTR_LEN(unescaped_cmd) == strlen(ZSTR_VAL(unescaped_cmd)) && "Must be a binary safe string");

ext/standard/filters.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1559,7 +1559,7 @@ static php_stream_filter *strfilter_convert_create(const char *filtername, zval
15591559
php_convert_filter *inst;
15601560
php_stream_filter *retval = NULL;
15611561

1562-
char *dot;
1562+
const char *dot;
15631563
int conv_mode = 0;
15641564

15651565
if (filterparams != NULL && Z_TYPE_P(filterparams) != IS_ARRAY) {

ext/standard/user_filters.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -259,8 +259,8 @@ static php_stream_filter *user_filter_factory_create(const char *filtername,
259259
len = strlen(filtername);
260260

261261
/* determine the classname/class entry */
262-
if (NULL == (fdat = zend_hash_str_find_ptr(BG(user_filter_map), (char*)filtername, len))) {
263-
char *period;
262+
if (NULL == (fdat = zend_hash_str_find_ptr(BG(user_filter_map), filtername, len))) {
263+
const char *period;
264264

265265
/* Userspace Filters using ambiguous wildcards could cause problems.
266266
i.e.: myfilter.foo.bar will always call into myfilter.foo.*
@@ -272,16 +272,16 @@ static php_stream_filter *user_filter_factory_create(const char *filtername,
272272

273273
/* Search for wildcard matches instead */
274274
memcpy(wildcard, filtername, len + 1); /* copy \0 */
275-
period = wildcard + (period - filtername);
276-
while (period) {
277-
ZEND_ASSERT(period[0] == '.');
278-
period[1] = '*';
279-
period[2] = '\0';
275+
char *new_period = wildcard + (period - filtername);
276+
while (new_period) {
277+
ZEND_ASSERT(new_period[0] == '.');
278+
new_period[1] = '*';
279+
new_period[2] = '\0';
280280
if (NULL != (fdat = zend_hash_str_find_ptr(BG(user_filter_map), wildcard, strlen(wildcard)))) {
281-
period = NULL;
281+
new_period = NULL;
282282
} else {
283-
*period = '\0';
284-
period = strrchr(wildcard, '.');
283+
*new_period = '\0';
284+
new_period = strrchr(wildcard, '.');
285285
}
286286
}
287287
efree(wildcard);
@@ -311,7 +311,7 @@ static php_stream_filter *user_filter_factory_create(const char *filtername,
311311
}
312312

313313
/* filtername */
314-
add_property_string(&obj, "filtername", (char*)filtername);
314+
add_property_string(&obj, "filtername", filtername);
315315

316316
/* and the parameters, if any */
317317
if (filterparams) {

main/fastcgi.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,7 @@ static int is_port_number(const char *bindpath)
641641

642642
int fcgi_listen(const char *path, int backlog)
643643
{
644-
char *s;
644+
const char *s;
645645
int tcp = 0;
646646
char host[MAXPATHLEN];
647647
short port = 0;

main/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -995,7 +995,7 @@ PHPAPI ZEND_COLD void php_verror(const char *docref, const char *params, int typ
995995
{
996996
zend_string *replace_origin = NULL;
997997
char *docref_buf = NULL, *target = NULL;
998-
char *docref_target = "", *docref_root = "";
998+
const char *docref_target = "", *docref_root = "";
999999
char *p;
10001000
const char *space = "";
10011001
const char *class_name = "";

main/network.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,7 @@ php_socket_t php_network_bind_socket_to_local_addr(const char *host, unsigned po
553553

554554
PHPAPI zend_result php_network_parse_network_address_with_port(const char *addr, size_t addrlen, struct sockaddr *sa, socklen_t *sl)
555555
{
556-
char *colon;
556+
const char *colon;
557557
char *tmp;
558558
zend_result ret = FAILURE;
559559
short port;

main/streams/filter.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ PHPAPI php_stream_filter *php_stream_filter_create(const char *filtername, zval
224224
const php_stream_filter_factory *factory = NULL;
225225
php_stream_filter *filter = NULL;
226226
size_t n;
227-
char *period;
227+
const char *period;
228228

229229
n = strlen(filtername);
230230

@@ -236,17 +236,17 @@ PHPAPI php_stream_filter *php_stream_filter_create(const char *filtername, zval
236236

237237
wildname = safe_emalloc(1, n, 3);
238238
memcpy(wildname, filtername, n+1);
239-
period = wildname + (period - filtername);
240-
while (period && !filter) {
241-
ZEND_ASSERT(period[0] == '.');
242-
period[1] = '*';
243-
period[2] = '\0';
239+
char *new_period = wildname + (period - filtername);
240+
while (new_period && !filter) {
241+
ZEND_ASSERT(new_period[0] == '.');
242+
new_period[1] = '*';
243+
new_period[2] = '\0';
244244
if (NULL != (factory = zend_hash_str_find_ptr(filter_hash, wildname, strlen(wildname)))) {
245245
filter = factory->create_filter(filtername, filterparams, persistent);
246246
}
247247

248-
*period = '\0';
249-
period = strrchr(wildname, '.');
248+
*new_period = '\0';
249+
new_period = strrchr(wildname, '.');
250250
}
251251
efree(wildname);
252252
}

0 commit comments

Comments
 (0)