Skip to content

Commit 3c111b3

Browse files
committed
apply review comments
1 parent a1cbd3c commit 3c111b3

3 files changed

Lines changed: 28 additions & 18 deletions

File tree

Zend/zend_execute.c

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2558,17 +2558,19 @@ ZEND_API ZEND_COLD zval* ZEND_FASTCALL zend_undefined_index_write(HashTable *ht,
25582558
return retval;
25592559
}
25602560

2561-
static zend_string *zend_find_similar_in_function_table(HashTable *ht, const char *lcname, size_t lcname_len)
2561+
static zend_string *zend_find_similar_in_function_table(const HashTable *ht, const char *lcname, size_t lcname_len)
25622562
{
25632563
zend_long threshold = lcname_len >= 8 ? 2 : 1;
25642564
zend_long best_dist = threshold + 1;
25652565
zend_string *best = NULL;
2566-
zend_string *key;
2567-
zval *val;
25682566

2569-
ZEND_HASH_MAP_FOREACH_STR_KEY_VAL(ht, key, val) {
2570-
if (!key || ZSTR_VAL(key)[0] == '\0') continue;
2571-
if (llabs((zend_long)lcname_len - (zend_long)ZSTR_LEN(key)) > threshold) continue;
2567+
ZEND_HASH_MAP_FOREACH_STR_KEY_VAL(ht, zend_string *key, zval *val) {
2568+
if (!key || ZSTR_VAL(key)[0] == '\0') {
2569+
continue;
2570+
}
2571+
if (llabs((zend_long)lcname_len - (zend_long)ZSTR_LEN(key)) > threshold) {
2572+
continue;
2573+
}
25722574
zend_long dist = zend_levenshtein(lcname, lcname_len, ZSTR_VAL(key), ZSTR_LEN(key));
25732575
if (dist > 0 && dist <= threshold && dist < best_dist) {
25742576
best_dist = dist;
@@ -2581,17 +2583,22 @@ static zend_string *zend_find_similar_in_function_table(HashTable *ht, const cha
25812583

25822584
static zend_string *zend_find_similar_function(const char *lcname, size_t lcname_len)
25832585
{
2584-
if (memchr(lcname, '\\', lcname_len)) return NULL;
2585-
if (lcname_len < 3) return NULL;
2586+
if (memchr(lcname, '\\', lcname_len)) {
2587+
return NULL;
2588+
}
2589+
if (lcname_len < 3) {
2590+
return NULL;
2591+
}
25862592
return zend_find_similar_in_function_table(EG(function_table), lcname, lcname_len);
25872593
}
25882594

25892595
static zend_string *zend_find_similar_method(const zend_class_entry *ce, const zend_string *method)
25902596
{
2591-
zend_string *lc_method = zend_string_tolower((zend_string *)method);
2597+
zend_string *lc_method = zend_string_alloc(ZSTR_LEN(method), 0);
25922598
zend_string *best = NULL;
2599+
zend_str_tolower_copy(ZSTR_VAL(lc_method), ZSTR_VAL(method), ZSTR_LEN(method));
25932600
if (ZSTR_LEN(lc_method) >= 3) {
2594-
best = zend_find_similar_in_function_table((HashTable *)&ce->function_table, ZSTR_VAL(lc_method), ZSTR_LEN(lc_method));
2601+
best = zend_find_similar_in_function_table(&ce->function_table, ZSTR_VAL(lc_method), ZSTR_LEN(lc_method));
25952602
}
25962603
zend_string_release(lc_method);
25972604
return best;

Zend/zend_execute_API.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1704,12 +1704,14 @@ static zend_string *zend_find_similar_in_class_table(const char *lcname, size_t
17041704
zend_long threshold = lcname_len >= 8 ? 2 : 1;
17051705
zend_long best_dist = threshold + 1;
17061706
zend_string *best = NULL;
1707-
zend_string *key;
1708-
zval *val;
17091707

1710-
ZEND_HASH_MAP_FOREACH_STR_KEY_VAL(EG(class_table), key, val) {
1711-
if (!key || ZSTR_VAL(key)[0] == '\0' || Z_TYPE_P(val) == IS_ALIAS_PTR) continue;
1712-
if (llabs((zend_long)lcname_len - (zend_long)ZSTR_LEN(key)) > threshold) continue;
1708+
ZEND_HASH_MAP_FOREACH_STR_KEY_VAL(EG(class_table), zend_string *key, zval *val) {
1709+
if (!key || ZSTR_VAL(key)[0] == '\0' || Z_TYPE_P(val) == IS_ALIAS_PTR) {
1710+
continue;
1711+
}
1712+
if (llabs((zend_long)lcname_len - (zend_long)ZSTR_LEN(key)) > threshold) {
1713+
continue;
1714+
}
17131715
zend_long dist = zend_levenshtein(lcname, lcname_len, ZSTR_VAL(key), ZSTR_LEN(key));
17141716
if (dist > 0 && dist <= threshold && dist < best_dist) {
17151717
best_dist = dist;
@@ -1722,8 +1724,9 @@ static zend_string *zend_find_similar_in_class_table(const char *lcname, size_t
17221724

17231725
static zend_string *zend_find_similar_class(const zend_string *class_name)
17241726
{
1725-
zend_string *lc_name = zend_string_tolower((zend_string *)class_name);
1727+
zend_string *lc_name = zend_string_alloc(ZSTR_LEN(class_name), 0);
17261728
zend_string *best = NULL;
1729+
zend_str_tolower_copy(ZSTR_VAL(lc_name), ZSTR_VAL(class_name), ZSTR_LEN(class_name));
17271730
if (ZSTR_LEN(lc_name) >= 3) {
17281731
best = zend_find_similar_in_class_table(ZSTR_VAL(lc_name), ZSTR_LEN(lc_name));
17291732
}

Zend/zend_string.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ ZEND_API zend_long zend_levenshtein(const char *s1, size_t l1, const char *s2, s
7777
size_t tmp_l = l1; l1 = l2; l2 = tmp_l;
7878
}
7979

80-
p1 = emalloc((l2 + 1) * sizeof(zend_long));
81-
p2 = emalloc((l2 + 1) * sizeof(zend_long));
80+
p1 = safe_emalloc(l2 + 1, sizeof(*p1), 0);
81+
p2 = safe_emalloc(l2 + 1, sizeof(*p2), 0);
8282

8383
for (i2 = 0; i2 <= l2; i2++) {
8484
p1[i2] = (zend_long)i2;

0 commit comments

Comments
 (0)