Skip to content

Commit efee76b

Browse files
committed
ext/json: Fix sign conversion warnings
1 parent 9dbcb91 commit efee76b

File tree

2 files changed

+22
-23
lines changed

2 files changed

+22
-23
lines changed

ext/json/json_encoder.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ static inline void php_json_encode_double(smart_str *buf, double d, int options)
112112

113113
static zend_result php_json_encode_array(smart_str *buf, zval *val, int options, php_json_encoder *encoder) /* {{{ */
114114
{
115-
int i, r, need_comma = 0;
115+
int r, need_comma = 0;
116116
HashTable *myht, *prop_ht;
117117

118118
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,
127127
zend_class_entry *ce = obj->ce;
128128
zend_property_info *prop_info;
129129
zval *prop;
130-
int i;
131130

132131
if (GC_IS_RECURSIVE(obj)) {
133132
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,
141140

142141
++encoder->depth;
143142

144-
for (i = 0; i < ce->default_properties_count; i++) {
143+
for (int i = 0; i < ce->default_properties_count; i++) {
145144
prop_info = ce->properties_info_table[i];
146145
if (!prop_info) {
147146
continue;
@@ -219,7 +218,7 @@ static zend_result php_json_encode_array(smart_str *buf, zval *val, int options,
219218

220219
++encoder->depth;
221220

222-
i = myht ? zend_hash_num_elements(myht) : 0;
221+
uint32_t i = myht ? zend_hash_num_elements(myht) : 0;
223222

224223
if (i > 0) {
225224
zend_string *key;

ext/json/json_scanner.re

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,16 @@
5353
#define PHP_JSON_INT_MAX_LENGTH (MAX_LENGTH_OF_LONG - 1)
5454

5555

56-
static void php_json_scanner_copy_string(php_json_scanner *s, int esc_size)
56+
static void php_json_scanner_copy_string(php_json_scanner *s, size_t esc_size)
5757
{
58-
size_t len = s->cursor - s->str_start - esc_size - 1;
58+
size_t len = (size_t)(s->cursor - s->str_start - esc_size - 1);
5959
if (len) {
6060
memcpy(s->pstr, s->str_start, len);
6161
s->pstr += len;
6262
}
6363
}
6464

65-
static int php_json_hex_to_int(char code)
65+
static int php_json_hex_to_int(unsigned char code)
6666
{
6767
if (code >= '0' && code <= '9') {
6868
return code - '0';
@@ -184,7 +184,7 @@ std:
184184
ZVAL_LONG(&s->value, ZEND_STRTOL((char *) s->token, NULL, 10));
185185
return PHP_JSON_T_INT;
186186
} else if (s->options & PHP_JSON_BIGINT_AS_STRING) {
187-
ZVAL_STRINGL(&s->value, (char *) s->token, s->cursor - s->token);
187+
ZVAL_STRINGL(&s->value, (char *) s->token, (size_t)(s->cursor - s->token));
188188
return PHP_JSON_T_STRING;
189189
} else {
190190
ZVAL_DOUBLE(&s->value, zend_strtod((char *) s->token, NULL));
@@ -258,7 +258,7 @@ std:
258258
}
259259
<STR_P1>["] {
260260
zend_string *str;
261-
size_t len = s->cursor - s->str_start - s->str_esc - 1 + s->utf8_invalid_count;
261+
size_t len = (size_t)(s->cursor - s->str_start - s->str_esc - 1 + s->utf8_invalid_count);
262262
if (len == 0) {
263263
PHP_JSON_CONDITION_SET(JS);
264264
ZVAL_EMPTY_STRING(&s->value);
@@ -299,24 +299,24 @@ std:
299299
<STR_P2_UTF,STR_P2_BIN>UTF16_1 {
300300
int utf16 = php_json_ucs2_to_int(s, 2);
301301
PHP_JSON_SCANNER_COPY_UTF();
302-
*(s->pstr++) = (char) utf16;
302+
*(s->pstr++) = (unsigned char) utf16;
303303
s->str_start = s->cursor;
304304
PHP_JSON_CONDITION_GOTO_STR_P2();
305305
}
306306
<STR_P2_UTF,STR_P2_BIN>UTF16_2 {
307307
int utf16 = php_json_ucs2_to_int(s, 3);
308308
PHP_JSON_SCANNER_COPY_UTF();
309-
*(s->pstr++) = (char) (0xc0 | (utf16 >> 6));
310-
*(s->pstr++) = (char) (0x80 | (utf16 & 0x3f));
309+
*(s->pstr++) = (unsigned char) (0xc0 | (utf16 >> 6));
310+
*(s->pstr++) = (unsigned char) (0x80 | (utf16 & 0x3f));
311311
s->str_start = s->cursor;
312312
PHP_JSON_CONDITION_GOTO_STR_P2();
313313
}
314314
<STR_P2_UTF,STR_P2_BIN>UTF16_3 {
315315
int utf16 = php_json_ucs2_to_int(s, 4);
316316
PHP_JSON_SCANNER_COPY_UTF();
317-
*(s->pstr++) = (char) (0xe0 | (utf16 >> 12));
318-
*(s->pstr++) = (char) (0x80 | ((utf16 >> 6) & 0x3f));
319-
*(s->pstr++) = (char) (0x80 | (utf16 & 0x3f));
317+
*(s->pstr++) = (unsigned char) (0xe0 | (utf16 >> 12));
318+
*(s->pstr++) = (unsigned char) (0x80 | ((utf16 >> 6) & 0x3f));
319+
*(s->pstr++) = (unsigned char) (0x80 | (utf16 & 0x3f));
320320
s->str_start = s->cursor;
321321
PHP_JSON_CONDITION_GOTO_STR_P2();
322322
}
@@ -326,15 +326,15 @@ std:
326326
utf16_lo = php_json_ucs2_to_int_ex(s, 4, 7);
327327
utf32 = ((utf16_lo & 0x3FF) << 10) + (utf16_hi & 0x3FF) + 0x10000;
328328
PHP_JSON_SCANNER_COPY_UTF_SP();
329-
*(s->pstr++) = (char) (0xf0 | (utf32 >> 18));
330-
*(s->pstr++) = (char) (0x80 | ((utf32 >> 12) & 0x3f));
331-
*(s->pstr++) = (char) (0x80 | ((utf32 >> 6) & 0x3f));
332-
*(s->pstr++) = (char) (0x80 | (utf32 & 0x3f));
329+
*(s->pstr++) = (unsigned char) (0xf0 | (utf32 >> 18));
330+
*(s->pstr++) = (unsigned char) (0x80 | ((utf32 >> 12) & 0x3f));
331+
*(s->pstr++) = (unsigned char) (0x80 | ((utf32 >> 6) & 0x3f));
332+
*(s->pstr++) = (unsigned char) (0x80 | (utf32 & 0x3f));
333333
s->str_start = s->cursor;
334334
PHP_JSON_CONDITION_GOTO_STR_P2();
335335
}
336336
<STR_P2_UTF,STR_P2_BIN>ESCPREF {
337-
char esc;
337+
unsigned char esc;
338338
PHP_JSON_SCANNER_COPY_ESC();
339339
switch (*s->cursor) {
340340
case 'b':
@@ -374,9 +374,9 @@ std:
374374
if (s->utf8_invalid) {
375375
PHP_JSON_SCANNER_COPY_ESC();
376376
if (s->options & PHP_JSON_INVALID_UTF8_SUBSTITUTE) {
377-
*(s->pstr++) = (char) (0xe0 | (0xfffd >> 12));
378-
*(s->pstr++) = (char) (0x80 | ((0xfffd >> 6) & 0x3f));
379-
*(s->pstr++) = (char) (0x80 | (0xfffd & 0x3f));
377+
*(s->pstr++) = (unsigned char) (0xe0 | (0xfffd >> 12));
378+
*(s->pstr++) = (unsigned char) (0x80 | ((0xfffd >> 6) & 0x3f));
379+
*(s->pstr++) = (unsigned char) (0x80 | (0xfffd & 0x3f));
380380
}
381381
s->str_start = s->cursor;
382382
}

0 commit comments

Comments
 (0)