Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Zend/Optimizer/dfa_pass.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
15 changes: 7 additions & 8 deletions Zend/Optimizer/zend_dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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),
Expand All @@ -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) {
Expand Down Expand Up @@ -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),
Expand All @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions Zend/Optimizer/zend_dump.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 4 additions & 6 deletions ext/date/php_date.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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 {
Expand All @@ -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];

Expand All @@ -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;
}
Expand Down
7 changes: 3 additions & 4 deletions ext/json/json_encoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
38 changes: 19 additions & 19 deletions ext/json/json_scanner.re
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -258,7 +258,7 @@ std:
}
<STR_P1>["] {
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);
Expand Down Expand Up @@ -299,24 +299,24 @@ std:
<STR_P2_UTF,STR_P2_BIN>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();
}
<STR_P2_UTF,STR_P2_BIN>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();
}
<STR_P2_UTF,STR_P2_BIN>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();
}
Expand All @@ -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();
}
<STR_P2_UTF,STR_P2_BIN>ESCPREF {
char esc;
unsigned char esc;
PHP_JSON_SCANNER_COPY_ESC();
switch (*s->cursor) {
case 'b':
Expand Down Expand Up @@ -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;
}
Expand Down
12 changes: 7 additions & 5 deletions ext/random/random.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -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;
Expand Down Expand Up @@ -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));
}

Expand Down
14 changes: 8 additions & 6 deletions ext/random/randomizer.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand All @@ -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) {
Expand Down
3 changes: 1 addition & 2 deletions ext/standard/url.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down