Shrink file name table size to `uint16_t`; ref
MODIFY
include/mruby/compile.h
include/mruby/compile.h
@@ -158,8 +158,8 @@ struct mrb_parser_state {
struct mrb_parser_message warn_buffer[10];
mrb_sym* filename_table;
- size_t filename_table_length;
- int current_filename_index;
+ uint16_t filename_table_length;
+ uint16_t current_filename_index;
struct mrb_jmpbuf* jmp;
};

MODIFY
mrbgems/mruby-compiler/core/parse.y
mrbgems/mruby-compiler/core/parse.y
@@ -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);
if (p->filename_table) {
@@ -5912,7 +5916,7 @@ mrb_parser_set_filename(struct mrb_parser_state *p, const char *f)
MRB_API char const*
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 {
return mrb_sym2name_len(p->mrb, p->filename_table[idx], NULL);
}

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