From a8cff779f5d02e68e4d7f037c93cb6a0d763cc32 Mon Sep 17 00:00:00 2001 From: Gina Peter Banyard Date: Mon, 3 Jun 2024 05:27:52 +0100 Subject: [PATCH 1/5] ext/json: Fix sign conversion warnings --- ext/json/json_encoder.c | 7 +++---- ext/json/json_scanner.re | 38 +++++++++++++++++++------------------- 2 files changed, 22 insertions(+), 23 deletions(-) diff --git a/ext/json/json_encoder.c b/ext/json/json_encoder.c index 4709c0e2be4a7..9ae6a97308998 100644 --- a/ext/json/json_encoder.c +++ b/ext/json/json_encoder.c @@ -112,7 +112,7 @@ static inline void php_json_encode_double(smart_str *buf, double d, int options) static zend_result php_json_encode_array(smart_str *buf, zval *val, int options, php_json_encoder *encoder) /* {{{ */ { - int i, r, need_comma = 0; + int r, need_comma = 0; HashTable *myht, *prop_ht; if (Z_TYPE_P(val) == IS_ARRAY) { @@ -127,7 +127,6 @@ static zend_result php_json_encode_array(smart_str *buf, zval *val, int options, zend_class_entry *ce = obj->ce; zend_property_info *prop_info; zval *prop; - int i; if (GC_IS_RECURSIVE(obj)) { encoder->error_code = PHP_JSON_ERROR_RECURSION; @@ -141,7 +140,7 @@ static zend_result php_json_encode_array(smart_str *buf, zval *val, int options, ++encoder->depth; - for (i = 0; i < ce->default_properties_count; i++) { + for (int i = 0; i < ce->default_properties_count; i++) { prop_info = ce->properties_info_table[i]; if (!prop_info) { continue; @@ -219,7 +218,7 @@ static zend_result php_json_encode_array(smart_str *buf, zval *val, int options, ++encoder->depth; - i = myht ? zend_hash_num_elements(myht) : 0; + uint32_t i = myht ? zend_hash_num_elements(myht) : 0; if (i > 0) { zend_string *key; diff --git a/ext/json/json_scanner.re b/ext/json/json_scanner.re index 1db43dd081a56..0debb3b03cb22 100644 --- a/ext/json/json_scanner.re +++ b/ext/json/json_scanner.re @@ -53,16 +53,16 @@ #define PHP_JSON_INT_MAX_LENGTH (MAX_LENGTH_OF_LONG - 1) -static void php_json_scanner_copy_string(php_json_scanner *s, int esc_size) +static void php_json_scanner_copy_string(php_json_scanner *s, size_t esc_size) { - size_t len = s->cursor - s->str_start - esc_size - 1; + size_t len = (size_t)(s->cursor - s->str_start - esc_size - 1); if (len) { memcpy(s->pstr, s->str_start, len); s->pstr += len; } } -static int php_json_hex_to_int(char code) +static int php_json_hex_to_int(unsigned char code) { if (code >= '0' && code <= '9') { return code - '0'; @@ -184,7 +184,7 @@ std: ZVAL_LONG(&s->value, ZEND_STRTOL((char *) s->token, NULL, 10)); return PHP_JSON_T_INT; } else if (s->options & PHP_JSON_BIGINT_AS_STRING) { - ZVAL_STRINGL(&s->value, (char *) s->token, s->cursor - s->token); + ZVAL_STRINGL(&s->value, (char *) s->token, (size_t)(s->cursor - s->token)); return PHP_JSON_T_STRING; } else { ZVAL_DOUBLE(&s->value, zend_strtod((char *) s->token, NULL)); @@ -258,7 +258,7 @@ std: } ["] { zend_string *str; - size_t len = s->cursor - s->str_start - s->str_esc - 1 + s->utf8_invalid_count; + size_t len = (size_t)(s->cursor - s->str_start - s->str_esc - 1 + s->utf8_invalid_count); if (len == 0) { PHP_JSON_CONDITION_SET(JS); ZVAL_EMPTY_STRING(&s->value); @@ -299,24 +299,24 @@ std: UTF16_1 { int utf16 = php_json_ucs2_to_int(s, 2); PHP_JSON_SCANNER_COPY_UTF(); - *(s->pstr++) = (char) utf16; + *(s->pstr++) = (unsigned char) utf16; s->str_start = s->cursor; PHP_JSON_CONDITION_GOTO_STR_P2(); } UTF16_2 { int utf16 = php_json_ucs2_to_int(s, 3); PHP_JSON_SCANNER_COPY_UTF(); - *(s->pstr++) = (char) (0xc0 | (utf16 >> 6)); - *(s->pstr++) = (char) (0x80 | (utf16 & 0x3f)); + *(s->pstr++) = (unsigned char) (0xc0 | (utf16 >> 6)); + *(s->pstr++) = (unsigned char) (0x80 | (utf16 & 0x3f)); s->str_start = s->cursor; PHP_JSON_CONDITION_GOTO_STR_P2(); } UTF16_3 { int utf16 = php_json_ucs2_to_int(s, 4); PHP_JSON_SCANNER_COPY_UTF(); - *(s->pstr++) = (char) (0xe0 | (utf16 >> 12)); - *(s->pstr++) = (char) (0x80 | ((utf16 >> 6) & 0x3f)); - *(s->pstr++) = (char) (0x80 | (utf16 & 0x3f)); + *(s->pstr++) = (unsigned char) (0xe0 | (utf16 >> 12)); + *(s->pstr++) = (unsigned char) (0x80 | ((utf16 >> 6) & 0x3f)); + *(s->pstr++) = (unsigned char) (0x80 | (utf16 & 0x3f)); s->str_start = s->cursor; PHP_JSON_CONDITION_GOTO_STR_P2(); } @@ -326,15 +326,15 @@ std: utf16_lo = php_json_ucs2_to_int_ex(s, 4, 7); utf32 = ((utf16_lo & 0x3FF) << 10) + (utf16_hi & 0x3FF) + 0x10000; PHP_JSON_SCANNER_COPY_UTF_SP(); - *(s->pstr++) = (char) (0xf0 | (utf32 >> 18)); - *(s->pstr++) = (char) (0x80 | ((utf32 >> 12) & 0x3f)); - *(s->pstr++) = (char) (0x80 | ((utf32 >> 6) & 0x3f)); - *(s->pstr++) = (char) (0x80 | (utf32 & 0x3f)); + *(s->pstr++) = (unsigned char) (0xf0 | (utf32 >> 18)); + *(s->pstr++) = (unsigned char) (0x80 | ((utf32 >> 12) & 0x3f)); + *(s->pstr++) = (unsigned char) (0x80 | ((utf32 >> 6) & 0x3f)); + *(s->pstr++) = (unsigned char) (0x80 | (utf32 & 0x3f)); s->str_start = s->cursor; PHP_JSON_CONDITION_GOTO_STR_P2(); } ESCPREF { - char esc; + unsigned char esc; PHP_JSON_SCANNER_COPY_ESC(); switch (*s->cursor) { case 'b': @@ -374,9 +374,9 @@ std: if (s->utf8_invalid) { PHP_JSON_SCANNER_COPY_ESC(); if (s->options & PHP_JSON_INVALID_UTF8_SUBSTITUTE) { - *(s->pstr++) = (char) (0xe0 | (0xfffd >> 12)); - *(s->pstr++) = (char) (0x80 | ((0xfffd >> 6) & 0x3f)); - *(s->pstr++) = (char) (0x80 | (0xfffd & 0x3f)); + *(s->pstr++) = (unsigned char) (0xe0 | (0xfffd >> 12)); + *(s->pstr++) = (unsigned char) (0x80 | ((0xfffd >> 6) & 0x3f)); + *(s->pstr++) = (unsigned char) (0x80 | (0xfffd & 0x3f)); } s->str_start = s->cursor; } From 2bce09961ac7f5ff1d708bf11dc3538445cb9363 Mon Sep 17 00:00:00 2001 From: Gina Peter Banyard Date: Mon, 3 Jun 2024 05:53:11 +0100 Subject: [PATCH 2/5] ext/random: Fix signess issues --- ext/random/random.c | 12 +++++++----- ext/random/randomizer.c | 14 ++++++++------ 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/ext/random/random.c b/ext/random/random.c index 7af7603238706..b83ac8d706ba2 100644 --- a/ext/random/random.c +++ b/ext/random/random.c @@ -338,9 +338,10 @@ PHPAPI zend_string *php_random_bin2hex_le(const void *ptr, const size_t len) i = 0; #ifdef WORDS_BIGENDIAN /* force little endian */ - for (zend_long j = (len - 1); 0 <= j; j--) { + for (size_t h = len; 0 < h; h--) { + size_t j = h-1; #else - for (zend_long j = 0; j < len; j++) { + for (size_t j = 0; j < len; j++) { #endif ZSTR_VAL(str)[i++] = hexconvtab[((unsigned char *) ptr)[j] >> 4]; ZSTR_VAL(str)[i++] = hexconvtab[((unsigned char *) ptr)[j] & 15]; @@ -362,9 +363,10 @@ PHPAPI bool php_random_hex2bin_le(zend_string *hexstr, void *dest) #ifdef WORDS_BIGENDIAN /* force little endian */ - for (zend_long j = (len - 1); 0 <= j; j--) { + for (size_t h = len; 0 < h; h--) { + size_t j = h-1; #else - for (zend_long j = 0; j < len; j++) { + for (size_t j = 0; j < len; j++) { #endif c = str[i++]; l = c & ~0x20; @@ -673,7 +675,7 @@ PHPAPI uint64_t php_random_generate_fallback_seed(void) uint64_t result = 0; - for (int i = 0; i < sizeof(result); i++) { + for (size_t i = 0; i < sizeof(result); i++) { result = result | (((uint64_t)RANDOM_G(fallback_seed)[i]) << (i * 8)); } diff --git a/ext/random/randomizer.c b/ext/random/randomizer.c index 909e81d7d676c..9d0545eefe4d8 100644 --- a/ext/random/randomizer.c +++ b/ext/random/randomizer.c @@ -277,18 +277,19 @@ PHP_METHOD(Random_Randomizer, getBytes) php_random_algo_with_state engine = randomizer->engine; zend_string *retval; - zend_long length; + zend_long user_length; size_t total_size = 0; ZEND_PARSE_PARAMETERS_START(1, 1) - Z_PARAM_LONG(length) + Z_PARAM_LONG(user_length) ZEND_PARSE_PARAMETERS_END(); - if (length < 1) { + if (user_length < 1) { zend_argument_value_error(1, "must be greater than 0"); RETURN_THROWS(); } + size_t length = (size_t)user_length; retval = zend_string_alloc(length, 0); while (total_size < length) { @@ -385,13 +386,13 @@ PHP_METHOD(Random_Randomizer, getBytesFromString) php_random_randomizer *randomizer = Z_RANDOM_RANDOMIZER_P(ZEND_THIS); php_random_algo_with_state engine = randomizer->engine; - zend_long length; + zend_long user_length; zend_string *source, *retval; size_t total_size = 0; ZEND_PARSE_PARAMETERS_START(2, 2); Z_PARAM_STR(source) - Z_PARAM_LONG(length) + Z_PARAM_LONG(user_length) ZEND_PARSE_PARAMETERS_END(); const size_t source_length = ZSTR_LEN(source); @@ -402,11 +403,12 @@ PHP_METHOD(Random_Randomizer, getBytesFromString) RETURN_THROWS(); } - if (length < 1) { + if (user_length < 1) { zend_argument_value_error(2, "must be greater than 0"); RETURN_THROWS(); } + size_t length = (size_t)user_length; retval = zend_string_alloc(length, 0); if (max_offset > 0xff) { From c7730b5d191876f55cac1af9e94e21ecded5a59a Mon Sep 17 00:00:00 2001 From: Gina Peter Banyard Date: Mon, 3 Jun 2024 05:55:36 +0100 Subject: [PATCH 3/5] ext/standard/url.c fix a [-Wsign-compare] warning --- ext/standard/url.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ext/standard/url.c b/ext/standard/url.c index e3d95768fb019..093650bf991b9 100644 --- a/ext/standard/url.c +++ b/ext/standard/url.c @@ -514,10 +514,9 @@ static zend_always_inline zend_string *php_url_encode_impl(const char *s, size_t _mm_storeu_si128((__m128i*)to, in); to += 16; } else { - int i; unsigned char xmm[16]; _mm_storeu_si128((__m128i*)xmm, in); - for (i = 0; i < sizeof(xmm); i++) { + for (size_t i = 0; i < sizeof(xmm); i++) { if ((bits & (0x1 << i))) { *to++ = xmm[i]; } else { From b7d6276be0bda67bb50b6b5583f29907722f24a6 Mon Sep 17 00:00:00 2001 From: Gina Peter Banyard Date: Mon, 3 Jun 2024 06:10:50 +0100 Subject: [PATCH 4/5] Zend/Optimizer: Fix some [-Wsign-compare] warnings --- Zend/Optimizer/dfa_pass.c | 2 +- Zend/Optimizer/zend_dump.c | 15 +++++++-------- Zend/Optimizer/zend_dump.h | 4 ++-- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/Zend/Optimizer/dfa_pass.c b/Zend/Optimizer/dfa_pass.c index b43b5fb8296cb..e281a26f5084c 100644 --- a/Zend/Optimizer/dfa_pass.c +++ b/Zend/Optimizer/dfa_pass.c @@ -1008,7 +1008,7 @@ static int zend_dfa_optimize_jmps(zend_op_array *op_array, zend_ssa *ssa) static bool zend_dfa_try_to_replace_result(zend_op_array *op_array, zend_ssa *ssa, int def, int cv_var) { int result_var = ssa->ops[def].result_def; - int cv = EX_NUM_TO_VAR(ssa->vars[cv_var].var); + uint32_t cv = EX_NUM_TO_VAR(ssa->vars[cv_var].var); if (result_var >= 0 && !(ssa->var_info[cv_var].type & MAY_BE_REF) diff --git a/Zend/Optimizer/zend_dump.c b/Zend/Optimizer/zend_dump.c index 77a953688e23a..b788b652979de 100644 --- a/Zend/Optimizer/zend_dump.c +++ b/Zend/Optimizer/zend_dump.c @@ -137,7 +137,7 @@ static void zend_dump_unused_op(const zend_op *opline, znode_op op, uint32_t fla } } -ZEND_API void zend_dump_var(const zend_op_array *op_array, uint8_t var_type, int var_num) +ZEND_API void zend_dump_var(const zend_op_array *op_array, uint8_t var_type, uint32_t var_num) { if (var_type == IS_CV && var_num < op_array->last_var) { fprintf(stderr, "CV%d($%s)", var_num, op_array->vars[var_num]->val); @@ -366,7 +366,7 @@ static void zend_dump_ssa_var_info(const zend_ssa *ssa, int ssa_var_num, uint32_ dump_flags); } -ZEND_API void zend_dump_ssa_var(const zend_op_array *op_array, const zend_ssa *ssa, int ssa_var_num, uint8_t var_type, int var_num, uint32_t dump_flags) +ZEND_API void zend_dump_ssa_var(const zend_op_array *op_array, const zend_ssa *ssa, int ssa_var_num, uint8_t var_type, uint32_t var_num, uint32_t dump_flags) { if (ssa_var_num >= 0) { fprintf(stderr, "#%d.", ssa_var_num); @@ -929,7 +929,6 @@ void zend_dump_op_array_name(const zend_op_array *op_array) ZEND_API void zend_dump_op_array(const zend_op_array *op_array, uint32_t dump_flags, const char *msg, const void *data) { - int i; const zend_cfg *cfg = NULL; const zend_ssa *ssa = NULL; zend_func_info *func_info = NULL; @@ -1015,7 +1014,7 @@ ZEND_API void zend_dump_op_array(const zend_op_array *op_array, uint32_t dump_fl } if (ssa && ssa->var_info) { - for (i = 0; i < op_array->last_var; i++) { + for (uint32_t i = 0; i < op_array->last_var; i++) { fprintf(stderr, " ; "); zend_dump_ssa_var(op_array, ssa, i, IS_CV, i, dump_flags); fprintf(stderr, "\n"); @@ -1043,7 +1042,7 @@ ZEND_API void zend_dump_op_array(const zend_op_array *op_array, uint32_t dump_fl } if (op_array->last_live_range && (dump_flags & ZEND_DUMP_LIVE_RANGES)) { fprintf(stderr, "LIVE RANGES:\n"); - for (i = 0; i < op_array->last_live_range; i++) { + for (int i = 0; i < op_array->last_live_range; i++) { fprintf(stderr, " %u: %04u - %04u ", EX_VAR_TO_NUM(op_array->live_range[i].var & ~ZEND_LIVE_MASK), @@ -1070,7 +1069,7 @@ ZEND_API void zend_dump_op_array(const zend_op_array *op_array, uint32_t dump_fl } if (op_array->last_try_catch) { fprintf(stderr, "EXCEPTION TABLE:\n"); - for (i = 0; i < op_array->last_try_catch; i++) { + for (int i = 0; i < op_array->last_try_catch; i++) { fprintf(stderr, " BB%u", cfg->map[op_array->try_catch_array[i].try_op]); if (op_array->try_catch_array[i].catch_op) { @@ -1103,7 +1102,7 @@ ZEND_API void zend_dump_op_array(const zend_op_array *op_array, uint32_t dump_fl } if (op_array->last_live_range && (dump_flags & ZEND_DUMP_LIVE_RANGES)) { fprintf(stderr, "LIVE RANGES:\n"); - for (i = 0; i < op_array->last_live_range; i++) { + for (int i = 0; i < op_array->last_live_range; i++) { fprintf(stderr, " %u: %04u - %04u ", EX_VAR_TO_NUM(op_array->live_range[i].var & ~ZEND_LIVE_MASK), @@ -1130,7 +1129,7 @@ ZEND_API void zend_dump_op_array(const zend_op_array *op_array, uint32_t dump_fl } if (op_array->last_try_catch) { fprintf(stderr, "EXCEPTION TABLE:\n"); - for (i = 0; i < op_array->last_try_catch; i++) { + for (int i = 0; i < op_array->last_try_catch; i++) { fprintf(stderr, " %04u", op_array->try_catch_array[i].try_op); diff --git a/Zend/Optimizer/zend_dump.h b/Zend/Optimizer/zend_dump.h index 1d77f75a69fc9..db8f762bfc495 100644 --- a/Zend/Optimizer/zend_dump.h +++ b/Zend/Optimizer/zend_dump.h @@ -40,8 +40,8 @@ void zend_dump_dominators(const zend_op_array *op_array, const zend_cfg *cfg); void zend_dump_dfg(const zend_op_array *op_array, const zend_cfg *cfg, const zend_dfg *dfg); void zend_dump_phi_placement(const zend_op_array *op_array, const zend_ssa *ssa); void zend_dump_ssa_variables(const zend_op_array *op_array, const zend_ssa *ssa, uint32_t dump_flags); -ZEND_API void zend_dump_ssa_var(const zend_op_array *op_array, const zend_ssa *ssa, int ssa_var_num, uint8_t var_type, int var_num, uint32_t dump_flags); -ZEND_API void zend_dump_var(const zend_op_array *op_array, uint8_t var_type, int var_num); +ZEND_API void zend_dump_ssa_var(const zend_op_array *op_array, const zend_ssa *ssa, int ssa_var_num, uint8_t var_type, uint32_t var_num, uint32_t dump_flags); +ZEND_API void zend_dump_var(const zend_op_array *op_array, uint8_t var_type, uint32_t var_num); void zend_dump_op_array_name(const zend_op_array *op_array); void zend_dump_const(const zval *zv); void zend_dump_ht(HashTable *ht); From aae2605eea56eaacd20ac5cace837d5948cf3703 Mon Sep 17 00:00:00 2001 From: Gina Peter Banyard Date: Mon, 3 Jun 2024 06:16:40 +0100 Subject: [PATCH 5/5] ext/date: Fix some [-Wsign-compare] warnings --- ext/date/php_date.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/ext/date/php_date.c b/ext/date/php_date.c index bbcaf27a4542f..3e19a8e182281 100644 --- a/ext/date/php_date.c +++ b/ext/date/php_date.c @@ -4294,7 +4294,7 @@ PHP_FUNCTION(timezone_transitions_get) { zval *object, element; php_timezone_obj *tzobj; - int begin = 0; + uint64_t begin = 0; bool found; zend_long timestamp_begin = ZEND_LONG_MIN, timestamp_end = INT32_MAX; @@ -4383,8 +4383,7 @@ PHP_FUNCTION(timezone_transitions_get) add_nominal(); } } else { - unsigned int i; - for (i = begin; i < tzobj->tzi.tz->bit64.timecnt; ++i) { + for (uint64_t i = begin; i < tzobj->tzi.tz->bit64.timecnt; ++i) { if (tzobj->tzi.tz->trans[i] < timestamp_end) { add(i, tzobj->tzi.tz->trans[i]); } else { @@ -4393,7 +4392,6 @@ PHP_FUNCTION(timezone_transitions_get) } } if (tzobj->tzi.tz->posix_info && tzobj->tzi.tz->posix_info->dst_end) { - int i, j; timelib_sll start_y, end_y, dummy_m, dummy_d; timelib_sll last_transition_ts = tzobj->tzi.tz->trans[tzobj->tzi.tz->bit64.timecnt - 1]; @@ -4403,12 +4401,12 @@ PHP_FUNCTION(timezone_transitions_get) /* Find out year for final boundary timestamp */ timelib_unixtime2date(timestamp_end, &end_y, &dummy_m, &dummy_d); - for (i = start_y; i <= end_y; i++) { + for (timelib_sll i = start_y; i <= end_y; i++) { timelib_posix_transitions transitions = { 0 }; timelib_get_transitions_for_year(tzobj->tzi.tz, i, &transitions); - for (j = 0; j < transitions.count; j++) { + for (size_t j = 0; j < transitions.count; j++) { if (transitions.times[j] <= last_transition_ts) { continue; }