@@ -89,8 +89,6 @@ void register_string_constants(INIT_FUNC_ARGS)
89
89
}
90
90
/* }}} */
91
91
92
- int php_tag_find (char * tag , size_t len , const char * set );
93
-
94
92
/* this is read-only, so it's ok */
95
93
ZEND_SET_ALIGNED (16 , static const char hexconvtab [ ]) = "0123456789abcdef" ;
96
94
@@ -695,11 +693,11 @@ PHP_FUNCTION(strcoll)
695
693
* it needs to be incrementing.
696
694
* Returns: FAILURE/SUCCESS whether the input was correct (i.e. no range errors)
697
695
*/
698
- static inline int php_charmask (const unsigned char * input , size_t len , char * mask )
696
+ static inline zend_result php_charmask (const unsigned char * input , size_t len , char * mask )
699
697
{
700
698
const unsigned char * end ;
701
699
unsigned char c ;
702
- int result = SUCCESS ;
700
+ zend_result result = SUCCESS ;
703
701
704
702
memset (mask , 0 , 256 );
705
703
for (end = input + len ; input < end ; input ++ ) {
@@ -1144,7 +1142,7 @@ PHP_FUNCTION(explode)
1144
1142
PHPAPI void php_implode (const zend_string * glue , HashTable * pieces , zval * return_value )
1145
1143
{
1146
1144
zval * tmp ;
1147
- int numelems ;
1145
+ uint32_t numelems ;
1148
1146
zend_string * str ;
1149
1147
char * cptr ;
1150
1148
size_t len = 0 ;
@@ -1606,7 +1604,7 @@ PHP_FUNCTION(pathinfo)
1606
1604
zval tmp ;
1607
1605
char * path , * dirname ;
1608
1606
size_t path_len ;
1609
- int have_basename ;
1607
+ bool have_basename ;
1610
1608
zend_long opt = PHP_PATHINFO_ALL ;
1611
1609
zend_string * ret = NULL ;
1612
1610
@@ -1744,16 +1742,14 @@ PHP_FUNCTION(stristr)
1744
1742
1745
1743
found = php_stristr (ZSTR_VAL (haystack ), ZSTR_VAL (needle ), ZSTR_LEN (haystack ), ZSTR_LEN (needle ));
1746
1744
1747
- if (found ) {
1748
- found_offset = found - ZSTR_VAL (haystack );
1749
- if (part ) {
1750
- RETVAL_STRINGL (ZSTR_VAL (haystack ), found_offset );
1751
- } else {
1752
- RETVAL_STRINGL (ZSTR_VAL (haystack ) + found_offset , ZSTR_LEN (haystack ) - found_offset );
1753
- }
1754
- } else {
1755
- RETVAL_FALSE ;
1745
+ if (UNEXPECTED (!found )) {
1746
+ RETURN_FALSE ;
1747
+ }
1748
+ found_offset = found - ZSTR_VAL (haystack );
1749
+ if (part ) {
1750
+ RETURN_STRINGL (ZSTR_VAL (haystack ), found_offset );
1756
1751
}
1752
+ RETURN_STRINGL (ZSTR_VAL (haystack ) + found_offset , ZSTR_LEN (haystack ) - found_offset );
1757
1753
}
1758
1754
/* }}} */
1759
1755
@@ -1774,15 +1770,14 @@ PHP_FUNCTION(strstr)
1774
1770
1775
1771
found = php_memnstr (ZSTR_VAL (haystack ), ZSTR_VAL (needle ), ZSTR_LEN (needle ), ZSTR_VAL (haystack ) + ZSTR_LEN (haystack ));
1776
1772
1777
- if (found ) {
1778
- found_offset = found - ZSTR_VAL (haystack );
1779
- if (part ) {
1780
- RETURN_STRINGL (ZSTR_VAL (haystack ), found_offset );
1781
- } else {
1782
- RETURN_STRINGL (found , ZSTR_LEN (haystack ) - found_offset );
1783
- }
1773
+ if (UNEXPECTED (!found )) {
1774
+ RETURN_FALSE ;
1784
1775
}
1785
- RETURN_FALSE ;
1776
+ found_offset = found - ZSTR_VAL (haystack );
1777
+ if (part ) {
1778
+ RETURN_STRINGL (ZSTR_VAL (haystack ), found_offset );
1779
+ }
1780
+ RETURN_STRINGL (ZSTR_VAL (haystack ) + found_offset , ZSTR_LEN (haystack ) - found_offset );
1786
1781
}
1787
1782
/* }}} */
1788
1783
@@ -1863,11 +1858,10 @@ PHP_FUNCTION(strpos)
1863
1858
ZSTR_VAL (needle ), ZSTR_LEN (needle ),
1864
1859
ZSTR_VAL (haystack ) + ZSTR_LEN (haystack ));
1865
1860
1866
- if (found ) {
1867
- RETURN_LONG (found - ZSTR_VAL (haystack ));
1868
- } else {
1861
+ if (UNEXPECTED (!found )) {
1869
1862
RETURN_FALSE ;
1870
1863
}
1864
+ RETURN_LONG (found - ZSTR_VAL (haystack ));
1871
1865
}
1872
1866
/* }}} */
1873
1867
@@ -1896,11 +1890,10 @@ PHP_FUNCTION(stripos)
1896
1890
found = (char * )php_memnistr (ZSTR_VAL (haystack ) + offset ,
1897
1891
ZSTR_VAL (needle ), ZSTR_LEN (needle ), ZSTR_VAL (haystack ) + ZSTR_LEN (haystack ));
1898
1892
1899
- if (found ) {
1900
- RETVAL_LONG (found - ZSTR_VAL (haystack ));
1901
- } else {
1902
- RETVAL_FALSE ;
1893
+ if (UNEXPECTED (!found )) {
1894
+ RETURN_FALSE ;
1903
1895
}
1896
+ RETURN_LONG (found - ZSTR_VAL (haystack ));
1904
1897
}
1905
1898
/* }}} */
1906
1899
@@ -1940,11 +1933,12 @@ PHP_FUNCTION(strrpos)
1940
1933
}
1941
1934
}
1942
1935
1943
- if ((found = zend_memnrstr (p , ZSTR_VAL (needle ), ZSTR_LEN (needle ), e ))) {
1944
- RETURN_LONG (found - ZSTR_VAL (haystack ));
1945
- }
1936
+ found = zend_memnrstr (p , ZSTR_VAL (needle ), ZSTR_LEN (needle ), e );
1946
1937
1947
- RETURN_FALSE ;
1938
+ if (UNEXPECTED (!found )) {
1939
+ RETURN_FALSE ;
1940
+ }
1941
+ RETURN_LONG (found - ZSTR_VAL (haystack ));
1948
1942
}
1949
1943
/* }}} */
1950
1944
@@ -2043,12 +2037,11 @@ PHP_FUNCTION(strrchr)
2043
2037
ZEND_PARSE_PARAMETERS_END ();
2044
2038
2045
2039
found = zend_memrchr (ZSTR_VAL (haystack ), * ZSTR_VAL (needle ), ZSTR_LEN (haystack ));
2046
- if (found ) {
2047
- found_offset = found - ZSTR_VAL (haystack );
2048
- RETURN_STRINGL (found , ZSTR_LEN (haystack ) - found_offset );
2049
- } else {
2040
+ if (UNEXPECTED (!found )) {
2050
2041
RETURN_FALSE ;
2051
2042
}
2043
+ found_offset = found - ZSTR_VAL (haystack );
2044
+ RETURN_STRINGL (found , ZSTR_LEN (haystack ) - found_offset );
2052
2045
}
2053
2046
/* }}} */
2054
2047
@@ -2782,7 +2775,7 @@ static void php_strtr_array(zval *return_value, zend_string *input, HashTable *p
2782
2775
zend_ulong num_key ;
2783
2776
zend_string * str_key ;
2784
2777
size_t len , pos , old_pos ;
2785
- int num_keys = 0 ;
2778
+ bool has_num_keys = false ;
2786
2779
size_t minlen = 128 * 1024 ;
2787
2780
size_t maxlen = 0 ;
2788
2781
HashTable str_hash ;
@@ -2799,10 +2792,10 @@ static void php_strtr_array(zval *return_value, zend_string *input, HashTable *p
2799
2792
/* check if original array has numeric keys */
2800
2793
ZEND_HASH_FOREACH_STR_KEY (pats , str_key ) {
2801
2794
if (UNEXPECTED (!str_key )) {
2802
- num_keys = 1 ;
2795
+ has_num_keys = true ;
2803
2796
} else {
2804
2797
len = ZSTR_LEN (str_key );
2805
- if (UNEXPECTED (len < 1 )) {
2798
+ if (UNEXPECTED (len == 0 )) {
2806
2799
php_error_docref (NULL , E_WARNING , "Ignoring replacement of empty string" );
2807
2800
continue ;
2808
2801
} else if (UNEXPECTED (len > slen )) {
@@ -2821,7 +2814,7 @@ static void php_strtr_array(zval *return_value, zend_string *input, HashTable *p
2821
2814
}
2822
2815
} ZEND_HASH_FOREACH_END ();
2823
2816
2824
- if (UNEXPECTED (num_keys )) {
2817
+ if (UNEXPECTED (has_num_keys )) {
2825
2818
zend_string * key_used ;
2826
2819
/* we have to rebuild HashTable with numeric keys */
2827
2820
zend_hash_init (& str_hash , zend_hash_num_elements (pats ), NULL , NULL , 0 );
@@ -2961,7 +2954,7 @@ static zend_always_inline zend_long count_chars(const char *p, zend_long length,
2961
2954
/* }}} */
2962
2955
2963
2956
/* {{{ php_char_to_str_ex */
2964
- static zend_string * php_char_to_str_ex (zend_string * str , char from , char * to , size_t to_len , int case_sensitivity , zend_long * replace_count )
2957
+ static zend_string * php_char_to_str_ex (zend_string * str , char from , char * to , size_t to_len , bool case_sensitivity , zend_long * replace_count )
2965
2958
{
2966
2959
zend_string * result ;
2967
2960
size_t char_count ;
@@ -3319,7 +3312,7 @@ PHP_FUNCTION(strtr)
3319
3312
ZSTR_VAL (str_key )[0 ],
3320
3313
ZSTR_VAL (replace ),
3321
3314
ZSTR_LEN (replace ),
3322
- 1 ,
3315
+ /* case_sensitive */ true ,
3323
3316
NULL ));
3324
3317
} else {
3325
3318
zend_long dummy ;
@@ -3455,7 +3448,7 @@ PHP_FUNCTION(similar_text)
3455
3448
{
3456
3449
zend_string * t1 , * t2 ;
3457
3450
zval * percent = NULL ;
3458
- int ac = ZEND_NUM_ARGS ();
3451
+ bool compute_percentage = ZEND_NUM_ARGS () >= 3 ;
3459
3452
size_t sim ;
3460
3453
3461
3454
ZEND_PARSE_PARAMETERS_START (2 , 3 )
@@ -3466,7 +3459,7 @@ PHP_FUNCTION(similar_text)
3466
3459
ZEND_PARSE_PARAMETERS_END ();
3467
3460
3468
3461
if (ZSTR_LEN (t1 ) + ZSTR_LEN (t2 ) == 0 ) {
3469
- if (ac > 2 ) {
3462
+ if (compute_percentage ) {
3470
3463
ZEND_TRY_ASSIGN_REF_DOUBLE (percent , 0 );
3471
3464
}
3472
3465
@@ -3475,7 +3468,7 @@ PHP_FUNCTION(similar_text)
3475
3468
3476
3469
sim = php_similar_char (ZSTR_VAL (t1 ), ZSTR_LEN (t1 ), ZSTR_VAL (t2 ), ZSTR_LEN (t2 ));
3477
3470
3478
- if (ac > 2 ) {
3471
+ if (compute_percentage ) {
3479
3472
ZEND_TRY_ASSIGN_REF_DOUBLE (percent , sim * 200.0 / (ZSTR_LEN (t1 ) + ZSTR_LEN (t2 )));
3480
3473
}
3481
3474
@@ -3893,8 +3886,7 @@ static zend_always_inline quad_word aarch64_contains_slash_chars(uint8x16_t x) {
3893
3886
3894
3887
static zend_always_inline char * aarch64_add_slashes (quad_word res , const char * source , char * target )
3895
3888
{
3896
- int i = 0 ;
3897
- for (; i < 16 ; i ++ ) {
3889
+ for (int i = 0 ; i < 16 ; i ++ ) {
3898
3890
char s = source [i ];
3899
3891
if (res .mem [i ] == 0 )
3900
3892
* target ++ = s ;
@@ -4156,7 +4148,7 @@ PHPAPI void php_stripslashes(zend_string *str)
4156
4148
/* {{{ php_str_replace_in_subject */
4157
4149
static zend_long php_str_replace_in_subject (
4158
4150
zend_string * search_str , HashTable * search_ht , zend_string * replace_str , HashTable * replace_ht ,
4159
- zend_string * subject_str , zval * result , int case_sensitivity
4151
+ zend_string * subject_str , zval * result , bool case_sensitivity
4160
4152
) {
4161
4153
zval * search_entry ;
4162
4154
zend_string * tmp_result ;
@@ -4317,7 +4309,7 @@ static zend_long php_str_replace_in_subject(
4317
4309
/* }}} */
4318
4310
4319
4311
/* {{{ php_str_replace_common */
4320
- static void php_str_replace_common (INTERNAL_FUNCTION_PARAMETERS , int case_sensitivity )
4312
+ static void php_str_replace_common (INTERNAL_FUNCTION_PARAMETERS , bool case_sensitivity )
4321
4313
{
4322
4314
zend_string * search_str ;
4323
4315
HashTable * search_ht ;
@@ -4832,10 +4824,11 @@ PHP_FUNCTION(parse_str)
4832
4824
* 0 start tag
4833
4825
* 1 first non-whitespace char seen
4834
4826
*/
4835
- int php_tag_find (char * tag , size_t len , const char * set ) {
4827
+ static bool php_tag_find (char * tag , size_t len , const char * set ) {
4836
4828
char c , * n ;
4837
4829
const char * t ;
4838
- int state = 0 , done = 0 ;
4830
+ int state = 0 ;
4831
+ bool done = 0 ;
4839
4832
char * norm ;
4840
4833
4841
4834
if (len == 0 ) {
@@ -5387,7 +5380,7 @@ PHP_FUNCTION(count_chars)
5387
5380
/* }}} */
5388
5381
5389
5382
/* {{{ php_strnatcmp */
5390
- static void php_strnatcmp (INTERNAL_FUNCTION_PARAMETERS , int fold_case )
5383
+ static void php_strnatcmp (INTERNAL_FUNCTION_PARAMETERS , bool is_case_insensitive )
5391
5384
{
5392
5385
zend_string * s1 , * s2 ;
5393
5386
@@ -5398,7 +5391,7 @@ static void php_strnatcmp(INTERNAL_FUNCTION_PARAMETERS, int fold_case)
5398
5391
5399
5392
RETURN_LONG (strnatcmp_ex (ZSTR_VAL (s1 ), ZSTR_LEN (s1 ),
5400
5393
ZSTR_VAL (s2 ), ZSTR_LEN (s2 ),
5401
- fold_case ));
5394
+ is_case_insensitive ));
5402
5395
}
5403
5396
/* }}} */
5404
5397
@@ -5409,11 +5402,18 @@ PHP_FUNCTION(strnatcmp)
5409
5402
}
5410
5403
/* }}} */
5411
5404
5405
+ /* {{{ Returns the result of case-insensitive string comparison using 'natural' algorithm */
5406
+ PHP_FUNCTION (strnatcasecmp )
5407
+ {
5408
+ php_strnatcmp (INTERNAL_FUNCTION_PARAM_PASSTHRU , 1 );
5409
+ }
5410
+ /* }}} */
5411
+
5412
5412
/* {{{ Returns numeric formatting information based on the current locale */
5413
5413
PHP_FUNCTION (localeconv )
5414
5414
{
5415
5415
zval grouping , mon_grouping ;
5416
- int len , i ;
5416
+ size_t len , i ;
5417
5417
5418
5418
ZEND_PARSE_PARAMETERS_NONE ();
5419
5419
@@ -5427,14 +5427,14 @@ PHP_FUNCTION(localeconv)
5427
5427
localeconv_r ( & currlocdata );
5428
5428
5429
5429
/* Grab the grouping data out of the array */
5430
- len = ( int ) strlen (currlocdata .grouping );
5430
+ len = strlen (currlocdata .grouping );
5431
5431
5432
5432
for (i = 0 ; i < len ; i ++ ) {
5433
5433
add_index_long (& grouping , i , currlocdata .grouping [i ]);
5434
5434
}
5435
5435
5436
5436
/* Grab the monetary grouping data out of the array */
5437
- len = ( int ) strlen (currlocdata .mon_grouping );
5437
+ len = strlen (currlocdata .mon_grouping );
5438
5438
5439
5439
for (i = 0 ; i < len ; i ++ ) {
5440
5440
add_index_long (& mon_grouping , i , currlocdata .mon_grouping [i ]);
@@ -5463,13 +5463,6 @@ PHP_FUNCTION(localeconv)
5463
5463
}
5464
5464
/* }}} */
5465
5465
5466
- /* {{{ Returns the result of case-insensitive string comparison using 'natural' algorithm */
5467
- PHP_FUNCTION (strnatcasecmp )
5468
- {
5469
- php_strnatcmp (INTERNAL_FUNCTION_PARAM_PASSTHRU , 1 );
5470
- }
5471
- /* }}} */
5472
-
5473
5466
/* {{{ Returns the number of times a substring occurs in the string */
5474
5467
PHP_FUNCTION (substr_count )
5475
5468
{
@@ -5741,7 +5734,7 @@ PHP_FUNCTION(str_rot13)
5741
5734
}
5742
5735
/* }}} */
5743
5736
5744
- static void php_string_shuffle (char * str , zend_long len ) /* {{{ */
5737
+ static void php_string_shuffle (char * str , size_t len ) /* {{{ */
5745
5738
{
5746
5739
zend_long n_elems , rnd_idx , n_left ;
5747
5740
char temp ;
@@ -5777,7 +5770,7 @@ PHP_FUNCTION(str_shuffle)
5777
5770
5778
5771
RETVAL_STRINGL (ZSTR_VAL (arg ), ZSTR_LEN (arg ));
5779
5772
if (Z_STRLEN_P (return_value ) > 1 ) {
5780
- php_string_shuffle (Z_STRVAL_P (return_value ), ( zend_long ) Z_STRLEN_P (return_value ));
5773
+ php_string_shuffle (Z_STRVAL_P (return_value ), Z_STRLEN_P (return_value ));
5781
5774
}
5782
5775
}
5783
5776
/* }}} */
0 commit comments