Skip to content

Commit 193b22f

Browse files
committed
ext/mbstring: pass true conversion map size around
1 parent 6f460fd commit 193b22f

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
@@ -3864,11 +3864,11 @@ PHP_FUNCTION(mb_convert_variables)
38643864
/* HTML numeric entities */
38653865

38663866
/* Convert PHP array to data structure required by mbfl_html_numeric_entity */
3867-
static uint32_t *make_conversion_map(HashTable *target_hash, int *convmap_size)
3867+
static uint32_t *make_conversion_map(HashTable *target_hash, size_t *conversion_map_size)
38683868
{
38693869
zval *hash_entry;
38703870

3871-
int n_elems = zend_hash_num_elements(target_hash);
3871+
size_t n_elems = *conversion_map_size = zend_hash_num_elements(target_hash);
38723872
if (n_elems % 4 != 0) {
38733873
zend_argument_value_error(2, "must have a multiple of 4 elements");
38743874
return NULL;
@@ -3881,13 +3881,12 @@ static uint32_t *make_conversion_map(HashTable *target_hash, int *convmap_size)
38813881
*mapelm++ = zval_get_long(hash_entry);
38823882
} ZEND_HASH_FOREACH_END();
38833883

3884-
*convmap_size = n_elems / 4;
38853884
return convmap;
38863885
}
38873886

3888-
static bool html_numeric_entity_convert(uint32_t w, uint32_t *convmap, int mapsize, uint32_t *retval)
3887+
static bool html_numeric_entity_convert(uint32_t w, uint32_t *convmap, size_t conversion_map_size, uint32_t *retval)
38893888
{
3890-
uint32_t *convmap_end = convmap + (mapsize * 4);
3889+
uint32_t *convmap_end = convmap + conversion_map_size;
38913890

38923891
for (uint32_t *mapelm = convmap; mapelm < convmap_end; mapelm += 4) {
38933892
uint32_t lo_code = mapelm[0];
@@ -3907,7 +3906,7 @@ static bool html_numeric_entity_convert(uint32_t w, uint32_t *convmap, int mapsi
39073906
return false;
39083907
}
39093908

3910-
static zend_string* html_numeric_entity_encode(zend_string *input, const mbfl_encoding *encoding, uint32_t *convmap, int mapsize, bool hex)
3909+
static zend_string* html_numeric_entity_encode(zend_string *input, const mbfl_encoding *encoding, uint32_t *convmap, size_t conversion_map_size, bool hex)
39113910
{
39123911
/* Each wchar which we get from decoding the input string may become up to
39133912
* 13 wchars when we convert it to an HTML entity */
@@ -3932,7 +3931,7 @@ static zend_string* html_numeric_entity_encode(zend_string *input, const mbfl_en
39323931
for (size_t i = 0; i < out_len; i++) {
39333932
uint32_t w = wchar_buf[i];
39343933

3935-
if (html_numeric_entity_convert(w, convmap, mapsize, &w)) {
3934+
if (html_numeric_entity_convert(w, convmap, conversion_map_size, &w)) {
39363935
*converted++ = '&';
39373936
*converted++ = '#';
39383937
if (hex) {
@@ -3977,7 +3976,7 @@ static zend_string* html_numeric_entity_encode(zend_string *input, const mbfl_en
39773976
PHP_FUNCTION(mb_encode_numericentity)
39783977
{
39793978
zend_string *encoding = NULL, *str;
3980-
int mapsize;
3979+
size_t conversion_map_size;
39813980
HashTable *target_hash;
39823981
bool is_hex = false;
39833982

@@ -3994,19 +3993,19 @@ PHP_FUNCTION(mb_encode_numericentity)
39943993
RETURN_THROWS();
39953994
}
39963995

3997-
uint32_t *convmap = make_conversion_map(target_hash, &mapsize);
3996+
uint32_t *convmap = make_conversion_map(target_hash, &conversion_map_size);
39983997
if (convmap == NULL) {
39993998
RETURN_THROWS();
40003999
}
40014000

4002-
RETVAL_STR(html_numeric_entity_encode(str, enc, convmap, mapsize, is_hex));
4001+
RETVAL_STR(html_numeric_entity_encode(str, enc, convmap, conversion_map_size, is_hex));
40034002
efree(convmap);
40044003
}
40054004
/* }}} */
40064005

4007-
static bool html_numeric_entity_deconvert(uint32_t number, uint32_t *convmap, int mapsize, uint32_t *retval)
4006+
static bool html_numeric_entity_deconvert(uint32_t number, uint32_t *convmap, size_t conversion_map_size, uint32_t *retval)
40084007
{
4009-
uint32_t *convmap_end = convmap + (mapsize * 4);
4008+
uint32_t *convmap_end = convmap + conversion_map_size;
40104009

40114010
for (uint32_t *mapelm = convmap; mapelm < convmap_end; mapelm += 4) {
40124011
uint32_t lo_code = mapelm[0];
@@ -4027,7 +4026,7 @@ static bool html_numeric_entity_deconvert(uint32_t number, uint32_t *convmap, in
40274026
#define DEC_ENTITY_MAXLEN 12 /* For "&#" and 10 decimal digits */
40284027
#define HEX_ENTITY_MAXLEN 11 /* For "&#x" and 8 hexadecimal digits */
40294028

4030-
static zend_string* html_numeric_entity_decode(zend_string *input, const mbfl_encoding *encoding, uint32_t *convmap, int mapsize)
4029+
static zend_string* html_numeric_entity_decode(zend_string *input, const mbfl_encoding *encoding, uint32_t *convmap, size_t conversion_map_size)
40314030
{
40324031
uint32_t wchar_buf[128], converted_buf[128];
40334032

@@ -4121,7 +4120,7 @@ static zend_string* html_numeric_entity_decode(zend_string *input, const mbfl_en
41214120
value = (value * 16) + 10 + (w - 'A');
41224121
}
41234122
}
4124-
if (html_numeric_entity_deconvert(value, convmap, mapsize, converted)) {
4123+
if (html_numeric_entity_deconvert(value, convmap, conversion_map_size, converted)) {
41254124
converted++;
41264125
if (*p2 == ';')
41274126
p2++;
@@ -4159,7 +4158,7 @@ static zend_string* html_numeric_entity_decode(zend_string *input, const mbfl_en
41594158
}
41604159
value = (value * 10) + (*p3++ - '0');
41614160
}
4162-
if (html_numeric_entity_deconvert(value, convmap, mapsize, converted)) {
4161+
if (html_numeric_entity_deconvert(value, convmap, conversion_map_size, converted)) {
41634162
converted++;
41644163
if (*p2 == ';')
41654164
p2++;
@@ -4209,7 +4208,7 @@ static zend_string* html_numeric_entity_decode(zend_string *input, const mbfl_en
42094208
PHP_FUNCTION(mb_decode_numericentity)
42104209
{
42114210
zend_string *encoding = NULL, *str;
4212-
int mapsize;
4211+
size_t conversion_map_size;
42134212
HashTable *target_hash;
42144213

42154214
ZEND_PARSE_PARAMETERS_START(2, 3)
@@ -4224,12 +4223,12 @@ PHP_FUNCTION(mb_decode_numericentity)
42244223
RETURN_THROWS();
42254224
}
42264225

4227-
uint32_t *convmap = make_conversion_map(target_hash, &mapsize);
4226+
uint32_t *convmap = make_conversion_map(target_hash, &conversion_map_size);
42284227
if (convmap == NULL) {
42294228
RETURN_THROWS();
42304229
}
42314230

4232-
RETVAL_STR(html_numeric_entity_decode(str, enc, convmap, mapsize));
4231+
RETVAL_STR(html_numeric_entity_decode(str, enc, convmap, conversion_map_size));
42334232
efree(convmap);
42344233
}
42354234
/* }}} */

0 commit comments

Comments
 (0)