Skip to content

Commit 92d3e78

Browse files
committed
On a 64-bit system, memory allocation is done in a single operation
1 parent 178fc2d commit 92d3e78

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

ext/intl/grapheme/grapheme_string.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1049,8 +1049,15 @@ PHP_FUNCTION(grapheme_levenshtein)
10491049
}
10501050

10511051
zend_long *p1, *p2, *tmp;
1052+
#if SIZEOF_SIZE_T == 8
1053+
/* strlen_2 is an int32_t, so it will not overflow. */
1054+
zend_long *pbuf = safe_emalloc(((size_t) strlen_2 + 1) * 2, sizeof(zend_long), 0);
1055+
p1 = pbuf;
1056+
p2 = p1 + (strlen_2 + 1);
1057+
#else
10521058
p1 = safe_emalloc(strlen_2 + 1, sizeof(zend_long), 0);
10531059
p2 = safe_emalloc(strlen_2 + 1, sizeof(zend_long), 0);
1060+
#endif
10541061

10551062
for (i2 = 0; i2 <= strlen_2; i2++) {
10561063
p1[i2] = i2 * cost_ins;
@@ -1098,8 +1105,12 @@ PHP_FUNCTION(grapheme_levenshtein)
10981105
retval = p1[strlen_2];
10991106
RETVAL_LONG(retval);
11001107

1108+
#if SIZEOF_SIZE_T == 8
1109+
efree(pbuf);
1110+
#else
11011111
efree(p2);
11021112
efree(p1);
1113+
#endif
11031114

11041115
out_collator:
11051116
ucol_close(collator);

0 commit comments

Comments
 (0)