Commit d90c5c8e authored by Yukihiro "Matz" Matsumoto's avatar Yukihiro "Matz" Matsumoto

Merge pull request #1303 from kyab/sirep_fix2

Fix crash on load *mrb
parents ec9fdd5c e9ebd6f8
...@@ -187,7 +187,6 @@ read_rite_section_irep(mrb_state *mrb, const uint8_t *bin) ...@@ -187,7 +187,6 @@ read_rite_section_irep(mrb_state *mrb, const uint8_t *bin)
{ {
int result; int result;
size_t sirep; size_t sirep;
size_t i;
uint32_t len; uint32_t len;
uint16_t nirep; uint16_t nirep;
uint16_t n; uint16_t n;
...@@ -200,14 +199,14 @@ read_rite_section_irep(mrb_state *mrb, const uint8_t *bin) ...@@ -200,14 +199,14 @@ read_rite_section_irep(mrb_state *mrb, const uint8_t *bin)
nirep = bin_to_uint16(header->nirep); nirep = bin_to_uint16(header->nirep);
//Read Binary Data Section //Read Binary Data Section
for (n = 0, i = sirep; n < nirep; n++, i++) { for (n = 0; n < nirep; n++) {
result = read_rite_irep_record(mrb, bin, &len); result = read_rite_irep_record(mrb, bin, &len);
if (result != MRB_DUMP_OK) if (result != MRB_DUMP_OK)
goto error_exit; goto error_exit;
bin += len; bin += len;
} }
result = sirep + bin_to_uint16(header->sirep); result = nirep;
error_exit: error_exit:
if (result < MRB_DUMP_OK) { if (result < MRB_DUMP_OK) {
irep_free(sirep, mrb); irep_free(sirep, mrb);
...@@ -368,7 +367,7 @@ mrb_read_irep(mrb_state *mrb, const uint8_t *bin) ...@@ -368,7 +367,7 @@ mrb_read_irep(mrb_state *mrb, const uint8_t *bin)
bin += bin_to_uint32(section_header->section_size); bin += bin_to_uint32(section_header->section_size);
} while (memcmp(section_header->section_identify, RITE_BINARY_EOF, sizeof(section_header->section_identify)) != 0); } while (memcmp(section_header->section_identify, RITE_BINARY_EOF, sizeof(section_header->section_identify)) != 0);
return total_nirep; return sirep;
} }
static void static void
...@@ -464,7 +463,6 @@ read_rite_section_irep_file(mrb_state *mrb, FILE *fp) ...@@ -464,7 +463,6 @@ read_rite_section_irep_file(mrb_state *mrb, FILE *fp)
{ {
int32_t result; int32_t result;
size_t sirep; size_t sirep;
size_t i;
uint16_t nirep; uint16_t nirep;
uint16_t n; uint16_t n;
uint32_t len, buf_size; uint32_t len, buf_size;
...@@ -488,7 +486,7 @@ read_rite_section_irep_file(mrb_state *mrb, FILE *fp) ...@@ -488,7 +486,7 @@ read_rite_section_irep_file(mrb_state *mrb, FILE *fp)
} }
//Read Binary Data Section //Read Binary Data Section
for (n = 0, i = sirep; n < nirep; n++, i++) { for (n = 0; n < nirep; n++) {
void *ptr; void *ptr;
if (fread(buf, record_header_size, 1, fp) == 0) { if (fread(buf, record_header_size, 1, fp) == 0) {
...@@ -516,7 +514,7 @@ read_rite_section_irep_file(mrb_state *mrb, FILE *fp) ...@@ -516,7 +514,7 @@ read_rite_section_irep_file(mrb_state *mrb, FILE *fp)
goto error_exit; goto error_exit;
} }
result = sirep + bin_to_uint16(header.sirep); result = nirep;
error_exit: error_exit:
if (buf) { if (buf) {
mrb_free(mrb, buf); mrb_free(mrb, buf);
...@@ -614,7 +612,7 @@ mrb_read_irep_file(mrb_state *mrb, FILE* fp) ...@@ -614,7 +612,7 @@ mrb_read_irep_file(mrb_state *mrb, FILE* fp)
fseek(fp, fpos + section_size, SEEK_SET); fseek(fp, fpos + section_size, SEEK_SET);
} while (memcmp(section_header.section_identify, RITE_BINARY_EOF, sizeof(section_header.section_identify)) != 0); } while (memcmp(section_header.section_identify, RITE_BINARY_EOF, sizeof(section_header.section_identify)) != 0);
return total_nirep; return sirep;
} }
mrb_value mrb_value
......
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