Skip to content

Commit e58f288

Browse files
authored
Do not allocate memory for zero length strings. (#1844)
Fixes #1821. JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
1 parent a504fd0 commit e58f288

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

Diff for: jerry-core/parser/js/js-lexer.c

+5
Original file line numberDiff line numberDiff line change
@@ -1197,6 +1197,11 @@ lexer_process_char_literal (parser_context_t *context_p, /**< context */
11971197
parser_raise_error (context_p, PARSER_ERR_LITERAL_LIMIT_REACHED);
11981198
}
11991199

1200+
if (length == 0)
1201+
{
1202+
has_escape = false;
1203+
}
1204+
12001205
literal_p = (lexer_literal_t *) parser_list_append (context_p, &context_p->literal_pool);
12011206
literal_p->prop.length = (uint16_t) length;
12021207
literal_p->type = literal_type;

Diff for: tests/jerry/regression-test-issue-1833.js

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright JS Foundation and other contributors, http://js.foundation
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
'\
16+
'

0 commit comments

Comments
 (0)