ext/json: Fix sign conversion warnings

This commit is contained in:
Gina Peter Banyard 2024-06-03 05:27:52 +01:00
parent 9dbcb91152
commit efee76b8e2
2 changed files with 22 additions and 23 deletions

View file

@ -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) /* {{{ */ 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; HashTable *myht, *prop_ht;
if (Z_TYPE_P(val) == IS_ARRAY) { 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_class_entry *ce = obj->ce;
zend_property_info *prop_info; zend_property_info *prop_info;
zval *prop; zval *prop;
int i;
if (GC_IS_RECURSIVE(obj)) { if (GC_IS_RECURSIVE(obj)) {
encoder->error_code = PHP_JSON_ERROR_RECURSION; 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; ++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]; prop_info = ce->properties_info_table[i];
if (!prop_info) { if (!prop_info) {
continue; continue;
@ -219,7 +218,7 @@ static zend_result php_json_encode_array(smart_str *buf, zval *val, int options,
++encoder->depth; ++encoder->depth;
i = myht ? zend_hash_num_elements(myht) : 0; uint32_t i = myht ? zend_hash_num_elements(myht) : 0;
if (i > 0) { if (i > 0) {
zend_string *key; zend_string *key;

View file

@ -53,16 +53,16 @@
#define PHP_JSON_INT_MAX_LENGTH (MAX_LENGTH_OF_LONG - 1) #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) { if (len) {
memcpy(s->pstr, s->str_start, len); memcpy(s->pstr, s->str_start, len);
s->pstr += 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') { if (code >= '0' && code <= '9') {
return code - '0'; return code - '0';
@ -184,7 +184,7 @@ std:
ZVAL_LONG(&s->value, ZEND_STRTOL((char *) s->token, NULL, 10)); ZVAL_LONG(&s->value, ZEND_STRTOL((char *) s->token, NULL, 10));
return PHP_JSON_T_INT; return PHP_JSON_T_INT;
} else if (s->options & PHP_JSON_BIGINT_AS_STRING) { } 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; return PHP_JSON_T_STRING;
} else { } else {
ZVAL_DOUBLE(&s->value, zend_strtod((char *) s->token, NULL)); ZVAL_DOUBLE(&s->value, zend_strtod((char *) s->token, NULL));
@ -258,7 +258,7 @@ std:
} }
<STR_P1>["] { <STR_P1>["] {
zend_string *str; 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) { if (len == 0) {
PHP_JSON_CONDITION_SET(JS); PHP_JSON_CONDITION_SET(JS);
ZVAL_EMPTY_STRING(&s->value); ZVAL_EMPTY_STRING(&s->value);
@ -299,24 +299,24 @@ std:
<STR_P2_UTF,STR_P2_BIN>UTF16_1 { <STR_P2_UTF,STR_P2_BIN>UTF16_1 {
int utf16 = php_json_ucs2_to_int(s, 2); int utf16 = php_json_ucs2_to_int(s, 2);
PHP_JSON_SCANNER_COPY_UTF(); PHP_JSON_SCANNER_COPY_UTF();
*(s->pstr++) = (char) utf16; *(s->pstr++) = (unsigned char) utf16;
s->str_start = s->cursor; s->str_start = s->cursor;
PHP_JSON_CONDITION_GOTO_STR_P2(); PHP_JSON_CONDITION_GOTO_STR_P2();
} }
<STR_P2_UTF,STR_P2_BIN>UTF16_2 { <STR_P2_UTF,STR_P2_BIN>UTF16_2 {
int utf16 = php_json_ucs2_to_int(s, 3); int utf16 = php_json_ucs2_to_int(s, 3);
PHP_JSON_SCANNER_COPY_UTF(); PHP_JSON_SCANNER_COPY_UTF();
*(s->pstr++) = (char) (0xc0 | (utf16 >> 6)); *(s->pstr++) = (unsigned char) (0xc0 | (utf16 >> 6));
*(s->pstr++) = (char) (0x80 | (utf16 & 0x3f)); *(s->pstr++) = (unsigned char) (0x80 | (utf16 & 0x3f));
s->str_start = s->cursor; s->str_start = s->cursor;
PHP_JSON_CONDITION_GOTO_STR_P2(); PHP_JSON_CONDITION_GOTO_STR_P2();
} }
<STR_P2_UTF,STR_P2_BIN>UTF16_3 { <STR_P2_UTF,STR_P2_BIN>UTF16_3 {
int utf16 = php_json_ucs2_to_int(s, 4); int utf16 = php_json_ucs2_to_int(s, 4);
PHP_JSON_SCANNER_COPY_UTF(); PHP_JSON_SCANNER_COPY_UTF();
*(s->pstr++) = (char) (0xe0 | (utf16 >> 12)); *(s->pstr++) = (unsigned char) (0xe0 | (utf16 >> 12));
*(s->pstr++) = (char) (0x80 | ((utf16 >> 6) & 0x3f)); *(s->pstr++) = (unsigned char) (0x80 | ((utf16 >> 6) & 0x3f));
*(s->pstr++) = (char) (0x80 | (utf16 & 0x3f)); *(s->pstr++) = (unsigned char) (0x80 | (utf16 & 0x3f));
s->str_start = s->cursor; s->str_start = s->cursor;
PHP_JSON_CONDITION_GOTO_STR_P2(); PHP_JSON_CONDITION_GOTO_STR_P2();
} }
@ -326,15 +326,15 @@ std:
utf16_lo = php_json_ucs2_to_int_ex(s, 4, 7); utf16_lo = php_json_ucs2_to_int_ex(s, 4, 7);
utf32 = ((utf16_lo & 0x3FF) << 10) + (utf16_hi & 0x3FF) + 0x10000; utf32 = ((utf16_lo & 0x3FF) << 10) + (utf16_hi & 0x3FF) + 0x10000;
PHP_JSON_SCANNER_COPY_UTF_SP(); PHP_JSON_SCANNER_COPY_UTF_SP();
*(s->pstr++) = (char) (0xf0 | (utf32 >> 18)); *(s->pstr++) = (unsigned char) (0xf0 | (utf32 >> 18));
*(s->pstr++) = (char) (0x80 | ((utf32 >> 12) & 0x3f)); *(s->pstr++) = (unsigned char) (0x80 | ((utf32 >> 12) & 0x3f));
*(s->pstr++) = (char) (0x80 | ((utf32 >> 6) & 0x3f)); *(s->pstr++) = (unsigned char) (0x80 | ((utf32 >> 6) & 0x3f));
*(s->pstr++) = (char) (0x80 | (utf32 & 0x3f)); *(s->pstr++) = (unsigned char) (0x80 | (utf32 & 0x3f));
s->str_start = s->cursor; s->str_start = s->cursor;
PHP_JSON_CONDITION_GOTO_STR_P2(); PHP_JSON_CONDITION_GOTO_STR_P2();
} }
<STR_P2_UTF,STR_P2_BIN>ESCPREF { <STR_P2_UTF,STR_P2_BIN>ESCPREF {
char esc; unsigned char esc;
PHP_JSON_SCANNER_COPY_ESC(); PHP_JSON_SCANNER_COPY_ESC();
switch (*s->cursor) { switch (*s->cursor) {
case 'b': case 'b':
@ -374,9 +374,9 @@ std:
if (s->utf8_invalid) { if (s->utf8_invalid) {
PHP_JSON_SCANNER_COPY_ESC(); PHP_JSON_SCANNER_COPY_ESC();
if (s->options & PHP_JSON_INVALID_UTF8_SUBSTITUTE) { if (s->options & PHP_JSON_INVALID_UTF8_SUBSTITUTE) {
*(s->pstr++) = (char) (0xe0 | (0xfffd >> 12)); *(s->pstr++) = (unsigned char) (0xe0 | (0xfffd >> 12));
*(s->pstr++) = (char) (0x80 | ((0xfffd >> 6) & 0x3f)); *(s->pstr++) = (unsigned char) (0x80 | ((0xfffd >> 6) & 0x3f));
*(s->pstr++) = (char) (0x80 | (0xfffd & 0x3f)); *(s->pstr++) = (unsigned char) (0x80 | (0xfffd & 0x3f));
} }
s->str_start = s->cursor; s->str_start = s->cursor;
} }