Skip to content

Commit 3e17afd

Browse files
committed
ext/mbstring: pass true conversion map size around
1 parent 700e4c5 commit 3e17afd

File tree

1 file changed

+17
-18
lines changed

1 file changed

+17
-18
lines changed

ext/mbstring/mbstring.c

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3663,11 +3663,11 @@ PHP_FUNCTION(mb_convert_variables)
36633663
/* HTML numeric entities */
36643664

36653665
/* Convert PHP array to data structure required by mbfl_html_numeric_entity */
3666-
static uint32_t *make_conversion_map(HashTable *target_hash, int *convmap_size)
3666+
static uint32_t *make_conversion_map(HashTable *target_hash, size_t *conversion_map_size)
36673667
{
36683668
zval *hash_entry;
36693669

3670-
int n_elems = zend_hash_num_elements(target_hash);
3670+
size_t n_elems = *conversion_map_size = zend_hash_num_elements(target_hash);
36713671
if (n_elems % 4 != 0) {
36723672
zend_argument_value_error(2, "must have a multiple of 4 elements");
36733673
return NULL;
@@ -3680,13 +3680,12 @@ static uint32_t *make_conversion_map(HashTable *target_hash, int *convmap_size)
36803680
*mapelm++ = zval_get_long(hash_entry);
36813681
} ZEND_HASH_FOREACH_END();
36823682

3683-
*convmap_size = n_elems / 4;
36843683
return convmap;
36853684
}
36863685

3687-
static bool html_numeric_entity_convert(uint32_t w, uint32_t *convmap, int mapsize, uint32_t *retval)
3686+
static bool html_numeric_entity_convert(uint32_t w, uint32_t *convmap, size_t conversion_map_size, uint32_t *retval)
36883687
{
3689-
uint32_t *convmap_end = convmap + (mapsize * 4);
3688+
uint32_t *convmap_end = convmap + conversion_map_size;
36903689

36913690
for (uint32_t *mapelm = convmap; mapelm < convmap_end; mapelm += 4) {
36923691
uint32_t lo_code = mapelm[0];
@@ -3706,7 +3705,7 @@ static bool html_numeric_entity_convert(uint32_t w, uint32_t *convmap, int mapsi
37063705
return false;
37073706
}
37083707

3709-
static zend_string* html_numeric_entity_encode(zend_string *input, const mbfl_encoding *encoding, uint32_t *convmap, int mapsize, bool hex)
3708+
static zend_string* html_numeric_entity_encode(zend_string *input, const mbfl_encoding *encoding, uint32_t *convmap, size_t conversion_map_size, bool hex)
37103709
{
37113710
/* Each wchar which we get from decoding the input string may become up to
37123711
* 13 wchars when we convert it to an HTML entity */
@@ -3731,7 +3730,7 @@ static zend_string* html_numeric_entity_encode(zend_string *input, const mbfl_en
37313730
for (size_t i = 0; i < out_len; i++) {
37323731
uint32_t w = wchar_buf[i];
37333732

3734-
if (html_numeric_entity_convert(w, convmap, mapsize, &w)) {
3733+
if (html_numeric_entity_convert(w, convmap, conversion_map_size, &w)) {
37353734
*converted++ = '&';
37363735
*converted++ = '#';
37373736
if (hex) {
@@ -3776,7 +3775,7 @@ static zend_string* html_numeric_entity_encode(zend_string *input, const mbfl_en
37763775
PHP_FUNCTION(mb_encode_numericentity)
37773776
{
37783777
zend_string *encoding = NULL, *str;
3779-
int mapsize;
3778+
size_t conversion_map_size;
37803779
HashTable *target_hash;
37813780
bool is_hex = false;
37823781

@@ -3793,19 +3792,19 @@ PHP_FUNCTION(mb_encode_numericentity)
37933792
RETURN_THROWS();
37943793
}
37953794

3796-
uint32_t *convmap = make_conversion_map(target_hash, &mapsize);
3795+
uint32_t *convmap = make_conversion_map(target_hash, &conversion_map_size);
37973796
if (convmap == NULL) {
37983797
RETURN_THROWS();
37993798
}
38003799

3801-
RETVAL_STR(html_numeric_entity_encode(str, enc, convmap, mapsize, is_hex));
3800+
RETVAL_STR(html_numeric_entity_encode(str, enc, convmap, conversion_map_size, is_hex));
38023801
efree(convmap);
38033802
}
38043803
/* }}} */
38053804

3806-
static bool html_numeric_entity_deconvert(uint32_t number, uint32_t *convmap, int mapsize, uint32_t *retval)
3805+
static bool html_numeric_entity_deconvert(uint32_t number, uint32_t *convmap, size_t conversion_map_size, uint32_t *retval)
38073806
{
3808-
uint32_t *convmap_end = convmap + (mapsize * 4);
3807+
uint32_t *convmap_end = convmap + conversion_map_size;
38093808

38103809
for (uint32_t *mapelm = convmap; mapelm < convmap_end; mapelm += 4) {
38113810
uint32_t lo_code = mapelm[0];
@@ -3826,7 +3825,7 @@ static bool html_numeric_entity_deconvert(uint32_t number, uint32_t *convmap, in
38263825
#define DEC_ENTITY_MAXLEN 12 /* For "&#" and 10 decimal digits */
38273826
#define HEX_ENTITY_MAXLEN 11 /* For "&#x" and 8 hexadecimal digits */
38283827

3829-
static zend_string* html_numeric_entity_decode(zend_string *input, const mbfl_encoding *encoding, uint32_t *convmap, int mapsize)
3828+
static zend_string* html_numeric_entity_decode(zend_string *input, const mbfl_encoding *encoding, uint32_t *convmap, size_t conversion_map_size)
38303829
{
38313830
uint32_t wchar_buf[128], converted_buf[128];
38323831

@@ -3920,7 +3919,7 @@ static zend_string* html_numeric_entity_decode(zend_string *input, const mbfl_en
39203919
value = (value * 16) + 10 + (w - 'A');
39213920
}
39223921
}
3923-
if (html_numeric_entity_deconvert(value, convmap, mapsize, converted)) {
3922+
if (html_numeric_entity_deconvert(value, convmap, conversion_map_size, converted)) {
39243923
converted++;
39253924
if (*p2 == ';')
39263925
p2++;
@@ -3958,7 +3957,7 @@ static zend_string* html_numeric_entity_decode(zend_string *input, const mbfl_en
39583957
}
39593958
value = (value * 10) + (*p3++ - '0');
39603959
}
3961-
if (html_numeric_entity_deconvert(value, convmap, mapsize, converted)) {
3960+
if (html_numeric_entity_deconvert(value, convmap, conversion_map_size, converted)) {
39623961
converted++;
39633962
if (*p2 == ';')
39643963
p2++;
@@ -4008,7 +4007,7 @@ static zend_string* html_numeric_entity_decode(zend_string *input, const mbfl_en
40084007
PHP_FUNCTION(mb_decode_numericentity)
40094008
{
40104009
zend_string *encoding = NULL, *str;
4011-
int mapsize;
4010+
size_t conversion_map_size;
40124011
HashTable *target_hash;
40134012

40144013
ZEND_PARSE_PARAMETERS_START(2, 3)
@@ -4023,12 +4022,12 @@ PHP_FUNCTION(mb_decode_numericentity)
40234022
RETURN_THROWS();
40244023
}
40254024

4026-
uint32_t *convmap = make_conversion_map(target_hash, &mapsize);
4025+
uint32_t *convmap = make_conversion_map(target_hash, &conversion_map_size);
40274026
if (convmap == NULL) {
40284027
RETURN_THROWS();
40294028
}
40304029

4031-
RETVAL_STR(html_numeric_entity_decode(str, enc, convmap, mapsize));
4030+
RETVAL_STR(html_numeric_entity_decode(str, enc, convmap, conversion_map_size));
40324031
efree(convmap);
40334032
}
40344033
/* }}} */

0 commit comments

Comments
 (0)