diff --git a/mrbgems/mruby-compiler/core/parse.y b/mrbgems/mruby-compiler/core/parse.y index 7c063609e..a144617d7 100644 --- a/mrbgems/mruby-compiler/core/parse.y +++ b/mrbgems/mruby-compiler/core/parse.y @@ -6934,11 +6934,12 @@ mrb_load_detect_file_cxt(mrb_state *mrb, FILE *fp, mrbc_context *c) binsize = bin_to_uint32(leading.h.binary_size); bin_obj = mrb_str_new(mrb, NULL, binsize); bin = (uint8_t *)RSTRING_PTR(bin_obj); - memcpy(bin, leading.b, bufsize); - if (binsize > bufsize && - fread(bin + bufsize, binsize - bufsize, 1, fp) == 0) { - binsize = bufsize; - /* The error is reported by mrb_load_irep_buf_cxt() */ + if (binsize > bufsize) { + memcpy(bin, leading.b, bufsize); + if (fread(bin + bufsize, binsize - bufsize, 1, fp) == 0) { + binsize = bufsize; + /* The error is reported by mrb_load_irep_buf_cxt() */ + } } result = mrb_load_irep_buf_cxt(mrb, bin, binsize, c); diff --git a/mrbgems/mruby-compiler/core/y.tab.c b/mrbgems/mruby-compiler/core/y.tab.c index d4a6b6363..046f02e55 100644 --- a/mrbgems/mruby-compiler/core/y.tab.c +++ b/mrbgems/mruby-compiler/core/y.tab.c @@ -13161,11 +13161,12 @@ mrb_load_detect_file_cxt(mrb_state *mrb, FILE *fp, mrbc_context *c) binsize = bin_to_uint32(leading.h.binary_size); bin_obj = mrb_str_new(mrb, NULL, binsize); bin = (uint8_t *)RSTRING_PTR(bin_obj); - memcpy(bin, leading.b, bufsize); - if (binsize > bufsize && - fread(bin + bufsize, binsize - bufsize, 1, fp) == 0) { - binsize = bufsize; - /* The error is reported by mrb_load_irep_buf_cxt() */ + if (binsize > bufsize) { + memcpy(bin, leading.b, bufsize); + if (fread(bin + bufsize, binsize - bufsize, 1, fp) == 0) { + binsize = bufsize; + /* The error is reported by mrb_load_irep_buf_cxt() */ + } } result = mrb_load_irep_buf_cxt(mrb, bin, binsize, c);