diff options
| author | Tatsuhiko Kubo <[email protected]> | 2014-08-28 05:19:09 +0900 |
|---|---|---|
| committer | Tatsuhiko Kubo <[email protected]> | 2014-08-28 05:19:09 +0900 |
| commit | 921798be01294f45dfcdce2133460a2e9a9f40ec (patch) | |
| tree | 3c6566b3f8beac508d7cb85e15846f22df5ccc05 /src | |
| parent | 7a25b53301bd92ec7dfd1490c3b8420c448670f0 (diff) | |
| download | mruby-921798be01294f45dfcdce2133460a2e9a9f40ec.tar.gz mruby-921798be01294f45dfcdce2133460a2e9a9f40ec.zip | |
Fix error handlings for fprintf().
Diffstat (limited to 'src')
| -rw-r--r-- | src/dump.c | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/src/dump.c b/src/dump.c index e67eabbc8..1eff501f9 100644 --- a/src/dump.c +++ b/src/dump.c @@ -987,11 +987,20 @@ mrb_dump_irep_cfunc(mrb_state *mrb, mrb_irep *irep, int debug_info, FILE *fp, co result = mrb_dump_irep(mrb, irep, debug_info, &bin, &bin_size); if (result == MRB_DUMP_OK) { - fprintf(fp, "#include <stdint.h>\n"); /* for uint8_t under at least Darwin */ - fprintf(fp, "const uint8_t %s[] = {", initname); + if (fprintf(fp, "#include <stdint.h>\n") < 0) { /* for uint8_t under at least Darwin */ + mrb_free(mrb, bin); + return MRB_DUMP_WRITE_FAULT; + } + if (fprintf(fp, "const uint8_t %s[] = {", initname) < 0) { + mrb_free(mrb, bin); + return MRB_DUMP_WRITE_FAULT; + } while (bin_idx < bin_size) { if (bin_idx % 16 == 0) fputs("\n", fp); - fprintf(fp, "0x%02x,", bin[bin_idx++]); + if (fprintf(fp, "0x%02x,", bin[bin_idx++]) < 0) { + mrb_free(mrb, bin); + return MRB_DUMP_WRITE_FAULT; + } } fputs("\n};\n", fp); } |
