summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2014-08-29 01:10:44 +0900
committerYukihiro "Matz" Matsumoto <[email protected]>2014-08-29 01:10:44 +0900
commita3c34c165b7ac73ad5559eda39335ae4fa142056 (patch)
tree9909af190a9aa1c3113f51aa952e0afdcd79a42e /src
parent9e4b0124781454e130e5f8e6a29d292d9711d8bf (diff)
parent7d9b5132a5bf2bc674f340798875aab3e15aeeff (diff)
downloadmruby-a3c34c165b7ac73ad5559eda39335ae4fa142056.tar.gz
mruby-a3c34c165b7ac73ad5559eda39335ae4fa142056.zip
Merge pull request #2572 from cubicdaiya/issues/fprintf_error_handlings
Fix error handlings for fprintf() and fputs() to file.
Diffstat (limited to 'src')
-rw-r--r--src/dump.c27
1 files changed, 22 insertions, 5 deletions
diff --git a/src/dump.c b/src/dump.c
index e67eabbc8..f529c4f02 100644
--- a/src/dump.c
+++ b/src/dump.c
@@ -987,13 +987,30 @@ 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 (bin_idx % 16 == 0) {
+ if (fputs("\n", fp) == EOF) {
+ mrb_free(mrb, bin);
+ return MRB_DUMP_WRITE_FAULT;
+ }
+ }
+ if (fprintf(fp, "0x%02x,", bin[bin_idx++]) < 0) {
+ mrb_free(mrb, bin);
+ return MRB_DUMP_WRITE_FAULT;
+ }
+ }
+ if (fputs("\n};\n", fp) == EOF) {
+ mrb_free(mrb, bin);
+ return MRB_DUMP_WRITE_FAULT;
}
- fputs("\n};\n", fp);
}
mrb_free(mrb, bin);