Skip to content

Commit 93ba579

Browse files
committed
ext/mbstring: pass true conversion map size around
1 parent 7501a18 commit 93ba579

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
@@ -3667,11 +3667,11 @@ PHP_FUNCTION(mb_convert_variables)
36673667
/* HTML numeric entities */
36683668

36693669
/* Convert PHP array to data structure required by mbfl_html_numeric_entity */
3670-
static uint32_t *make_conversion_map(HashTable *target_hash, int *convmap_size)
3670+
static uint32_t *make_conversion_map(HashTable *target_hash, size_t *conversion_map_size)
36713671
{
36723672
zval *hash_entry;
36733673

3674-
int n_elems = zend_hash_num_elements(target_hash);
3674+
size_t n_elems = *conversion_map_size = zend_hash_num_elements(target_hash);
36753675
if (n_elems % 4 != 0) {
36763676
zend_argument_value_error(2, "must have a multiple of 4 elements");
36773677
return NULL;
@@ -3684,13 +3684,12 @@ static uint32_t *make_conversion_map(HashTable *target_hash, int *convmap_size)
36843684
*mapelm++ = zval_get_long(hash_entry);
36853685
} ZEND_HASH_FOREACH_END();
36863686

3687-
*convmap_size = n_elems / 4;
36883687
return convmap;
36893688
}
36903689

3691-
static bool html_numeric_entity_convert(uint32_t w, uint32_t *convmap, int mapsize, uint32_t *retval)
3690+
static bool html_numeric_entity_convert(uint32_t w, uint32_t *convmap, size_t conversion_map_size, uint32_t *retval)
36923691
{
3693-
uint32_t *convmap_end = convmap + (mapsize * 4);
3692+
uint32_t *convmap_end = convmap + conversion_map_size;
36943693

36953694
for (uint32_t *mapelm = convmap; mapelm < convmap_end; mapelm += 4) {
36963695
uint32_t lo_code = mapelm[0];
@@ -3710,7 +3709,7 @@ static bool html_numeric_entity_convert(uint32_t w, uint32_t *convmap, int mapsi
37103709
return false;
37113710
}
37123711

3713-
static zend_string* html_numeric_entity_encode(zend_string *input, const mbfl_encoding *encoding, uint32_t *convmap, int mapsize, bool hex)
3712+
static zend_string* html_numeric_entity_encode(zend_string *input, const mbfl_encoding *encoding, uint32_t *convmap, size_t conversion_map_size, bool hex)
37143713
{
37153714
/* Each wchar which we get from decoding the input string may become up to
37163715
* 13 wchars when we convert it to an HTML entity */
@@ -3735,7 +3734,7 @@ static zend_string* html_numeric_entity_encode(zend_string *input, const mbfl_en
37353734
for (size_t i = 0; i < out_len; i++) {
37363735
uint32_t w = wchar_buf[i];
37373736

3738-
if (html_numeric_entity_convert(w, convmap, mapsize, &w)) {
3737+
if (html_numeric_entity_convert(w, convmap, conversion_map_size, &w)) {
37393738
*converted++ = '&';
37403739
*converted++ = '#';
37413740
if (hex) {
@@ -3780,7 +3779,7 @@ static zend_string* html_numeric_entity_encode(zend_string *input, const mbfl_en
37803779
PHP_FUNCTION(mb_encode_numericentity)
37813780
{
37823781
zend_string *encoding = NULL, *str;
3783-
int mapsize;
3782+
size_t conversion_map_size;
37843783
HashTable *target_hash;
37853784
bool is_hex = false;
37863785

@@ -3797,19 +3796,19 @@ PHP_FUNCTION(mb_encode_numericentity)
37973796
RETURN_THROWS();
37983797
}
37993798

3800-
uint32_t *convmap = make_conversion_map(target_hash, &mapsize);
3799+
uint32_t *convmap = make_conversion_map(target_hash, &conversion_map_size);
38013800
if (convmap == NULL) {
38023801
RETURN_THROWS();
38033802
}
38043803

3805-
RETVAL_STR(html_numeric_entity_encode(str, enc, convmap, mapsize, is_hex));
3804+
RETVAL_STR(html_numeric_entity_encode(str, enc, convmap, conversion_map_size, is_hex));
38063805
efree(convmap);
38073806
}
38083807
/* }}} */
38093808

3810-
static bool html_numeric_entity_deconvert(uint32_t number, uint32_t *convmap, int mapsize, uint32_t *retval)
3809+
static bool html_numeric_entity_deconvert(uint32_t number, uint32_t *convmap, size_t conversion_map_size, uint32_t *retval)
38113810
{
3812-
uint32_t *convmap_end = convmap + (mapsize * 4);
3811+
uint32_t *convmap_end = convmap + conversion_map_size;
38133812

38143813
for (uint32_t *mapelm = convmap; mapelm < convmap_end; mapelm += 4) {
38153814
uint32_t lo_code = mapelm[0];
@@ -3830,7 +3829,7 @@ static bool html_numeric_entity_deconvert(uint32_t number, uint32_t *convmap, in
38303829
#define DEC_ENTITY_MAXLEN 12 /* For "&#" and 10 decimal digits */
38313830
#define HEX_ENTITY_MAXLEN 11 /* For "&#x" and 8 hexadecimal digits */
38323831

3833-
static zend_string* html_numeric_entity_decode(zend_string *input, const mbfl_encoding *encoding, uint32_t *convmap, int mapsize)
3832+
static zend_string* html_numeric_entity_decode(zend_string *input, const mbfl_encoding *encoding, uint32_t *convmap, size_t conversion_map_size)
38343833
{
38353834
uint32_t wchar_buf[128], converted_buf[128];
38363835

@@ -3924,7 +3923,7 @@ static zend_string* html_numeric_entity_decode(zend_string *input, const mbfl_en
39243923
value = (value * 16) + 10 + (w - 'A');
39253924
}
39263925
}
3927-
if (html_numeric_entity_deconvert(value, convmap, mapsize, converted)) {
3926+
if (html_numeric_entity_deconvert(value, convmap, conversion_map_size, converted)) {
39283927
converted++;
39293928
if (*p2 == ';')
39303929
p2++;
@@ -3962,7 +3961,7 @@ static zend_string* html_numeric_entity_decode(zend_string *input, const mbfl_en
39623961
}
39633962
value = (value * 10) + (*p3++ - '0');
39643963
}
3965-
if (html_numeric_entity_deconvert(value, convmap, mapsize, converted)) {
3964+
if (html_numeric_entity_deconvert(value, convmap, conversion_map_size, converted)) {
39663965
converted++;
39673966
if (*p2 == ';')
39683967
p2++;
@@ -4012,7 +4011,7 @@ static zend_string* html_numeric_entity_decode(zend_string *input, const mbfl_en
40124011
PHP_FUNCTION(mb_decode_numericentity)
40134012
{
40144013
zend_string *encoding = NULL, *str;
4015-
int mapsize;
4014+
size_t conversion_map_size;
40164015
HashTable *target_hash;
40174016

40184017
ZEND_PARSE_PARAMETERS_START(2, 3)
@@ -4027,12 +4026,12 @@ PHP_FUNCTION(mb_decode_numericentity)
40274026
RETURN_THROWS();
40284027
}
40294028

4030-
uint32_t *convmap = make_conversion_map(target_hash, &mapsize);
4029+
uint32_t *convmap = make_conversion_map(target_hash, &conversion_map_size);
40314030
if (convmap == NULL) {
40324031
RETURN_THROWS();
40334032
}
40344033

4035-
RETVAL_STR(html_numeric_entity_decode(str, enc, convmap, mapsize));
4034+
RETVAL_STR(html_numeric_entity_decode(str, enc, convmap, conversion_map_size));
40364035
efree(convmap);
40374036
}
40384037
/* }}} */

0 commit comments

Comments
 (0)