Shrink file name table size to `uint16_t`; ref #4138

parent faf51f82
...@@ -158,8 +158,8 @@ struct mrb_parser_state { ...@@ -158,8 +158,8 @@ struct mrb_parser_state {
struct mrb_parser_message warn_buffer[10]; struct mrb_parser_message warn_buffer[10];
mrb_sym* filename_table; mrb_sym* filename_table;
size_t filename_table_length; uint16_t filename_table_length;
int current_filename_index; uint16_t current_filename_index;
struct mrb_jmpbuf* jmp; struct mrb_jmpbuf* jmp;
}; };
......
...@@ -5900,7 +5900,11 @@ mrb_parser_set_filename(struct mrb_parser_state *p, const char *f) ...@@ -5900,7 +5900,11 @@ mrb_parser_set_filename(struct mrb_parser_state *p, const char *f)
} }
} }
p->current_filename_index = (int)p->filename_table_length++; if (p->filename_table_length == UINT16_MAX) {
yyerror(p, "too many files to compile");
return;
}
p->current_filename_index = p->filename_table_length++;
new_table = (mrb_sym*)parser_palloc(p, sizeof(mrb_sym) * p->filename_table_length); new_table = (mrb_sym*)parser_palloc(p, sizeof(mrb_sym) * p->filename_table_length);
if (p->filename_table) { if (p->filename_table) {
...@@ -5912,7 +5916,7 @@ mrb_parser_set_filename(struct mrb_parser_state *p, const char *f) ...@@ -5912,7 +5916,7 @@ mrb_parser_set_filename(struct mrb_parser_state *p, const char *f)
MRB_API char const* MRB_API char const*
mrb_parser_get_filename(struct mrb_parser_state* p, uint16_t idx) { mrb_parser_get_filename(struct mrb_parser_state* p, uint16_t idx) {
if (idx >= p->filename_table_length) { return NULL; } if (idx >= p->filename_table_length) return NULL;
else { else {
return mrb_sym2name_len(p->mrb, p->filename_table[idx], NULL); return mrb_sym2name_len(p->mrb, p->filename_table[idx], NULL);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment