Skip to content

Commit 708f66a

Browse files
galpeterLaszloLango
authored andcommitted
Fix accessing the contents of a direct string (#2261)
In the `ecma_string_get_chars` method the contents of a direct string is accessed incorrectly. It tries to extract the magic string id from the string pointer but the direct string does not need this step. JerryScript-DCO-1.0-Signed-off-by: Peter Gal [email protected]
1 parent ba22072 commit 708f66a

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

jerry-core/ecma/base/ecma-helpers-string.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1450,14 +1450,13 @@ ecma_string_get_chars (const ecma_string_t *string_p, /**< ecma-string */
14501450
lit_magic_string_ex_id_t id = (lit_magic_string_ex_id_t) ECMA_GET_DIRECT_STRING_VALUE (string_p);
14511451

14521452
size = lit_get_magic_string_ex_size (id);
1453+
result_p = lit_get_magic_string_ex_utf8 (id);
14531454
length = 0;
14541455

14551456
if (unlikely (*flags_p & ECMA_STRING_FLAG_IS_ASCII))
14561457
{
1457-
length = lit_utf8_string_length (lit_get_magic_string_ex_utf8 (string_p->u.magic_string_ex_id), size);
1458+
length = lit_utf8_string_length (result_p, size);
14581459
}
1459-
1460-
result_p = lit_get_magic_string_ex_utf8 (id);
14611460
break;
14621461
}
14631462
}

tests/unit-core/test-api.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1118,6 +1118,15 @@ main (void)
11181118

11191119
jerry_release_value (args[0]);
11201120

1121+
const char *test_magic_str_access_src_p = "'console'.charAt(6) == 'e'";
1122+
res = jerry_eval ((const jerry_char_t *) test_magic_str_access_src_p,
1123+
strlen (test_magic_str_access_src_p),
1124+
false);
1125+
TEST_ASSERT (jerry_value_is_boolean (res));
1126+
TEST_ASSERT (jerry_get_boolean_value (res) == true);
1127+
1128+
jerry_release_value (res);
1129+
11211130
cesu8_length = jerry_get_string_length (args[1]);
11221131
cesu8_sz = jerry_get_string_size (args[1]);
11231132

0 commit comments

Comments
 (0)