Skip to content

Commit 7d3bb85

Browse files
committed
Fix buffer size in Number.prototype.toFixed()
JerryScript-DCO-1.0-Signed-off-by: Dániel Bátyai [email protected]
1 parent 216dc25 commit 7d3bb85

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

jerry-core/ecma/builtin-objects/ecma-builtin-number-prototype.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,13 @@ ecma_builtin_number_prototype_object_to_fixed (ecma_value_t this_arg, /**< this
268268
else
269269
{
270270
/* Buffer that is used to construct the string. */
271-
int buffer_size = (exponent > 0) ? exponent + frac_digits + 1 : frac_digits + 2;
271+
int buffer_size = (exponent > 0) ? exponent + frac_digits + 2 : frac_digits + 3;
272+
273+
if (is_negative)
274+
{
275+
buffer_size++;
276+
}
277+
272278
JERRY_ASSERT (buffer_size > 0);
273279
MEM_DEFINE_LOCAL_ARRAY (buff, buffer_size, ecma_char_t);
274280

@@ -360,6 +366,7 @@ ecma_builtin_number_prototype_object_to_fixed (ecma_value_t this_arg, /**< this
360366
}
361367
}
362368

369+
JERRY_ASSERT (p - buff < buffer_size);
363370
/* String terminator. */
364371
*p = 0;
365372
ecma_string_t* str = ecma_new_ecma_string ((ecma_char_t *) buff);

0 commit comments

Comments
 (0)