Skip to content

Commit c0bb229

Browse files
committed
Fix invalid read of mem reported by valgrind
1 parent cb77933 commit c0bb229

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

ext/standard/math.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1264,16 +1264,18 @@ PHPAPI zend_string *_php_math_number_format_long(zend_long num, int dec, const c
12641264
*t++ = '1';
12651265
if (thousand_sep && (count%3) == 0) {
12661266
memcpy(t, thousand_sep, thousand_sep_len);
1267-
t += thousand_sep_len;
1267+
memcpy(t + thousand_sep_len, ZSTR_VAL(tmpbuf)+1, reslen - thousand_sep_len - 1);
1268+
} else {
1269+
memcpy(t, ZSTR_VAL(tmpbuf)+1, reslen - 1);
12681270
}
1269-
memcpy(t, ZSTR_VAL(tmpbuf)+1, reslen - 1);
12701271
} else {
12711272
*t++ = '1';
12721273
if (thousand_sep && (count%3) == 0) {
12731274
memcpy(t, thousand_sep, thousand_sep_len);
1274-
t += thousand_sep_len;
1275+
memcpy(t + thousand_sep_len, ZSTR_VAL(tmpbuf), reslen - thousand_sep_len);
1276+
} else {
1277+
memcpy(t, ZSTR_VAL(tmpbuf), reslen);
12751278
}
1276-
memcpy(t, ZSTR_VAL(tmpbuf), reslen);
12771279
}
12781280
}
12791281

0 commit comments

Comments
 (0)