From aaaf38b6fdd4bff6810eae491bd4186f32ea14d0 Mon Sep 17 00:00:00 2001 From: Michael Beck Date: Thu, 30 Jun 2005 09:57:43 +0000 Subject: [PATCH] check file handle, so it does not crash if the file could not be opened [r6153] --- ir/stat/stat_dmp.c | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/ir/stat/stat_dmp.c b/ir/stat/stat_dmp.c index 6ed10e0ec..13a660b6e 100644 --- a/ir/stat/stat_dmp.c +++ b/ir/stat/stat_dmp.c @@ -137,6 +137,9 @@ static void simple_dump_opt_hash(dumper_t *dmp, pset *set, int index) */ static void simple_dump_real_func_calls(dumper_t *dmp, counter_t *cnt) { + if (! dmp->f) + return; + if (! cnt_eq(cnt, 0)) { fprintf(dmp->f, "\nReal Function Calls optimized:\n"); fprintf(dmp->f, "%-16s %8u\n", @@ -149,6 +152,9 @@ static void simple_dump_real_func_calls(dumper_t *dmp, counter_t *cnt) */ static void simple_dump_tail_recursion(dumper_t *dmp, unsigned num_tail_recursion) { + if (! dmp->f) + return; + if (num_tail_recursion > 0) { fprintf(dmp->f, "\nTail recursion optimized:\n"); fprintf(dmp->f, "%-16s %8u\n", "Call", num_tail_recursion); @@ -160,6 +166,9 @@ static void simple_dump_tail_recursion(dumper_t *dmp, unsigned num_tail_recursio */ static void simple_dump_edges(dumper_t *dmp, counter_t *cnt) { + if (! dmp->f) + return; + fprintf(dmp->f, "%-16s %8d\n", "Edges", cnt->cnt[0]); } @@ -171,6 +180,9 @@ static void simple_dump_graph(dumper_t *dmp, graph_entry_t *entry) int i, dump_opts = 1; block_entry_t *b_entry; + if (! dmp->f) + return; + if (entry->irg) { ir_graph *const_irg = get_const_code_irg(); @@ -258,6 +270,9 @@ static void simple_dump_const_tbl(dumper_t *dmp, const constant_info_t *tbl) int i; counter_t sum; + if (! dmp->f) + return; + cnt_clr(&sum); fprintf(dmp->f, "\nConstant Information:\n"); @@ -296,6 +311,9 @@ static void simple_init(dumper_t *dmp, const char *name) snprintf(fname, sizeof(fname), "%s.txt", name); dmp->f = fopen(fname, "w"); + if (! dmp->f) { + perror(fname); + } } /** @@ -303,7 +321,8 @@ static void simple_init(dumper_t *dmp, const char *name) */ static void simple_finish(dumper_t *dmp) { - fclose(dmp->f); + if (dmp->f) + fclose(dmp->f); dmp->f = NULL; } @@ -364,9 +383,11 @@ static void csv_count_nodes(dumper_t *dmp, graph_entry_t *graph, counter_t cnt[] static void csv_dump_graph(dumper_t *dmp, graph_entry_t *entry) { const char *name; - counter_t cnt[4]; + if (! dmp->f) + return; + if (entry->irg && !entry->is_deleted) { ir_graph *const_irg = get_const_code_irg(); @@ -411,6 +432,9 @@ static void csv_init(dumper_t *dmp, const char *name) snprintf(fname, sizeof(fname), "%s.csv", name); dmp->f = fopen(fname, "a"); + if (! dmp->f) { + perror(fname); + } } /** @@ -418,7 +442,8 @@ static void csv_init(dumper_t *dmp, const char *name) */ static void csv_finish(dumper_t *dmp) { - fclose(dmp->f); + if (dmp->f) + fclose(dmp->f); dmp->f = NULL; } -- 2.20.1