Skip to content

Commit 4b83e30

Browse files
author
Slavey Karadzhov
committed
Try to allocate enough memory for the char buffers.
JerryScript-DCO-1.0-Signed-off-by: Slavey Karadzhov [email protected]
1 parent 2c83fd7 commit 4b83e30

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

targets/esp8266/source/jerry_extapi.c

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,23 @@ DELCARE_HANDLER(print) {
6666
{
6767
if (jerry_value_is_string (args_p[cc]))
6868
{
69-
static char buffer[128];
70-
jerry_size_t size, maxsize;
71-
size = jerry_get_string_size (args_p[0]);
72-
maxsize = MIN(size, 126);
69+
char *buffer;
70+
jerry_size_t size = jerry_get_string_size (args_p[0]);
71+
buffer = (char *) malloc(size + 1);
72+
73+
if(!buffer)
74+
{
75+
// not enough memory for this string.
76+
printf("[<too-long-string>]");
77+
continue;
78+
}
79+
7380
jerry_string_to_char_buffer (args_p[cc],
7481
(jerry_char_t *) buffer,
75-
maxsize);
82+
size);
7683
*(buffer + size) = 0;
7784
printf("[%s] ", buffer);
85+
free (buffer);
7886
}
7987
else
8088
{

0 commit comments

Comments
 (0)