Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
mruby
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
mruby
Commits
d4d807b7
Commit
d4d807b7
authored
Jul 13, 2016
by
Yukihiro "Matz" Matsumoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
relax string length limitation to 64KB; fix #2725
parent
2e74a931
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
19 deletions
+41
-19
include/mruby/compile.h
include/mruby/compile.h
+6
-3
mrbgems/mruby-compiler/core/parse.y
mrbgems/mruby-compiler/core/parse.y
+35
-16
No files found.
include/mruby/compile.h
View file @
d4d807b7
...
...
@@ -102,7 +102,8 @@ struct mrb_parser_heredoc_info {
mrb_ast_node
*
doc
;
};
#define MRB_PARSER_BUF_SIZE 1024
#define MRB_PARSER_TOKBUF_MAX 65536
#define MRB_PARSER_TOKBUF_SIZE 256
/* parser structure */
struct
mrb_parser_state
{
...
...
@@ -130,8 +131,10 @@ struct mrb_parser_state {
mrb_ast_node
*
locals
;
mrb_ast_node
*
pb
;
char
buf
[
MRB_PARSER_BUF_SIZE
];
int
bidx
;
char
*
tokbuf
;
char
buf
[
MRB_PARSER_TOKBUF_SIZE
];
int
tidx
;
int
tsiz
;
mrb_ast_node
*
all_heredocs
;
/* list of mrb_parser_heredoc_info* */
mrb_ast_node
*
heredocs_from_nextline
;
...
...
mrbgems/mruby-compiler/core/parse.y
View file @
d4d807b7
...
...
@@ -3573,7 +3573,12 @@ skips(parser_state *p, const char *s)
static int
newtok(parser_state *p)
{
p->bidx = 0;
if (p->tokbuf != p->buf) {
mrb_free(p->mrb, p->tokbuf);
p->tokbuf = p->buf;
p->tsiz = MRB_PARSER_TOKBUF_SIZE;
}
p->tidx = 0;
return p->column - 1;
}
...
...
@@ -3581,7 +3586,7 @@ static void
tokadd(parser_state *p, int32_t c)
{
char utf8[4];
unsigned
len;
int i,
len;
/* mrb_assert(-0x10FFFF <= c && c <= 0xFF); */
if (c >= 0) {
...
...
@@ -3615,42 +3620,51 @@ tokadd(parser_state *p, int32_t c)
len = 4;
}
}
if (p->bidx+len <= MRB_PARSER_BUF_SIZE) {
unsigned i;
for (i = 0; i < len; i++) {
p->buf[p->bidx++] = utf8[i];
if (p->tidx+len >= p->tsiz) {
if (p->tsiz >= MRB_PARSER_TOKBUF_MAX) {
p->tidx += len;
return;
}
p->tsiz *= 2;
if (p->tokbuf == p->buf) {
p->tokbuf = (char*)mrb_malloc(p->mrb, p->tsiz);
memcpy(p->tokbuf, p->buf, MRB_PARSER_TOKBUF_SIZE);
}
else {
p->tokbuf = (char*)mrb_realloc(p->mrb, p->tokbuf, p->tsiz);
}
}
for (i = 0; i < len; i++) {
p->tokbuf[p->tidx++] = utf8[i];
}
}
static int
toklast(parser_state *p)
{
return p->
buf[p->b
idx-1];
return p->
tokbuf[p->t
idx-1];
}
static void
tokfix(parser_state *p)
{
int i = p->bidx, imax = MRB_PARSER_BUF_SIZE - 1;
if (i > imax) {
i = imax;
if (p->tidx >= MRB_PARSER_TOKBUF_MAX) {
p->tidx = MRB_PARSER_TOKBUF_MAX-1;
yyerror(p, "string too long (truncated)");
}
p->
buf[i
] = '\0';
p->
tokbuf[p->tidx
] = '\0';
}
static const char*
tok(parser_state *p)
{
return p->buf;
return p->
tok
buf;
}
static int
toklen(parser_state *p)
{
return p->
b
idx;
return p->
t
idx;
}
#define IS_ARG() (p->lstate == EXPR_ARG || p->lstate == EXPR_CMDARG)
...
...
@@ -5196,7 +5210,7 @@ parser_yylex(parser_state *p)
c = nextc(p);
}
if (c < 0) {
if (p->
b
idx == 1) {
if (p->
t
idx == 1) {
yyerror(p, "incomplete instance variable syntax");
}
else {
...
...
@@ -5205,7 +5219,7 @@ parser_yylex(parser_state *p)
return 0;
}
else if (isdigit(c)) {
if (p->
b
idx == 1) {
if (p->
t
idx == 1) {
yyerror_i(p, "'@%c' is not allowed as an instance variable name", c);
}
else {
...
...
@@ -5486,6 +5500,8 @@ mrb_parser_new(mrb_state *mrb)
#if defined(PARSER_TEST) || defined(PARSER_DEBUG)
yydebug = 1;
#endif
p->tsiz = MRB_PARSER_TOKBUF_SIZE;
p->tokbuf = p->buf;
p->lex_strterm = NULL;
p->all_heredocs = p->parsing_heredoc = NULL;
...
...
@@ -5501,6 +5517,9 @@ mrb_parser_new(mrb_state *mrb)
MRB_API void
mrb_parser_free(parser_state *p) {
mrb_pool_close(p->pool);
if (p->tokbuf != p->buf) {
mrb_free(p->mrb, p->tokbuf);
}
}
MRB_API mrbc_context*
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment