Skip to content

Commit 600e4a8

Browse files
authored
tree-wide: Refactor with zend_string_ends_with* (#23216)
1 parent 09a4b6d commit 600e4a8

6 files changed

Lines changed: 10 additions & 14 deletions

File tree

ext/odbc/php_odbc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1015,7 +1015,7 @@ PHP_FUNCTION(odbc_execute)
10151015

10161016
if (ZSTR_LEN(tmpstr) > 2 &&
10171017
ZSTR_VAL(tmpstr)[0] == '\'' &&
1018-
ZSTR_VAL(tmpstr)[ZSTR_LEN(tmpstr) - 1] == '\'') {
1018+
zend_string_ends_with_literal(tmpstr, "'")) {
10191019

10201020
if (UNEXPECTED(zend_str_has_nul_byte(tmpstr))) {
10211021
odbc_release_params(result, params);

ext/opcache/ZendAccelerator.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1519,8 +1519,8 @@ static void zend_accel_add_key(zend_string *key, zend_accel_hash_entry *bucket)
15191519

15201520
static zend_always_inline bool is_phar_file(const zend_string *filename)
15211521
{
1522-
return filename && ZSTR_LEN(filename) >= sizeof(".phar") &&
1523-
!memcmp(ZSTR_VAL(filename) + ZSTR_LEN(filename) - (sizeof(".phar")-1), ".phar", sizeof(".phar")-1) &&
1522+
return filename &&
1523+
zend_string_ends_with_literal(filename, ".phar") &&
15241524
!strstr(ZSTR_VAL(filename), "://");
15251525
}
15261526

ext/pgsql/pgsql.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3427,13 +3427,13 @@ static zend_result pgsql_copy_from_query(PGconn *pgsql, PGresult *pgsql_result,
34273427
}
34283428

34293429
int result;
3430-
if (ZSTR_LEN(tmp) > 0 && ZSTR_VAL(tmp)[ZSTR_LEN(tmp) - 1] != '\n') {
3430+
if (ZSTR_LEN(tmp) == 0 || zend_string_ends_with_literal(tmp, "\n")) {
3431+
result = PQputCopyData(pgsql, ZSTR_VAL(tmp), ZSTR_LEN(tmp));
3432+
} else {
34313433
char *zquery = zend_cstr_append_char(
34323434
ZSTR_VAL(tmp), ZSTR_LEN(tmp), '\n');
34333435
result = PQputCopyData(pgsql, zquery, ZSTR_LEN(tmp) + 1);
34343436
efree(zquery);
3435-
} else {
3436-
result = PQputCopyData(pgsql, ZSTR_VAL(tmp), ZSTR_LEN(tmp));
34373437
}
34383438

34393439
zend_tmp_string_release(tmp_tmp);

ext/phar/phar_object.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4251,7 +4251,7 @@ ZEND_ATTRIBUTE_NONNULL_ARGS(1, 3, 5) static int extract_helper(const phar_archiv
42514251
if (FAILURE == phar_extract_file(overwrite, entry, path_to, error)) return -1;
42524252
extracted++;
42534253
} ZEND_HASH_FOREACH_END();
4254-
} else if (ZSTR_LEN(search) > 0 && '/' == ZSTR_VAL(search)[ZSTR_LEN(search) - 1]) {
4254+
} else if (zend_string_ends_with_literal(search, "/")) {
42554255
/* ends in "/" -- extract all entries having that prefix */
42564256
ZEND_HASH_MAP_FOREACH_PTR(&archive->manifest, entry) {
42574257
if (!zend_string_starts_with(entry->filename, search)) continue;

ext/session/session.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -876,7 +876,7 @@ static PHP_INI_MH(OnUpdateRfc1867Freq)
876876
return FAILURE;
877877
}
878878

879-
if (ZSTR_LEN(new_value) > 0 && ZSTR_VAL(new_value)[ZSTR_LEN(new_value) - 1] == '%') {
879+
if (zend_string_ends_with_literal(new_value, "%")) {
880880
if (new_freq > 100) {
881881
php_error_docref(NULL, E_WARNING, "session.upload_progress.freq must be less than or equal to 100%%");
882882
return FAILURE;

ext/soap/php_http.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -341,13 +341,9 @@ static php_stream* http_connect(zval* this_ptr, php_uri *uri, bool use_ssl, php_
341341
static bool in_domain(const zend_string *host, const zend_string *domain)
342342
{
343343
if (ZSTR_VAL(domain)[0] == '.') {
344-
if (ZSTR_LEN(host) > ZSTR_LEN(domain)) {
345-
return zend_string_equals_cstr(domain, ZSTR_VAL(host) + ZSTR_LEN(host) - ZSTR_LEN(domain), ZSTR_LEN(domain));
346-
} else {
347-
return false;
348-
}
344+
return zend_string_ends_with(host, domain);
349345
} else {
350-
return zend_string_equals(host,domain);
346+
return zend_string_equals(host, domain);
351347
}
352348
}
353349

0 commit comments

Comments
 (0)