From efee76b8e22a20a663a245b75fd13c8c486ee7b7 Mon Sep 17 00:00:00 2001 From: Gina Peter Banyard Date: Mon, 3 Jun 2024 05:27:52 +0100 Subject: [PATCH] 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 4709c0e2be4..9ae6a973089 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 1db43dd081a..0debb3b03cb 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; }