From a51b19f667731104d1277df71b26daa2d3816189 Mon Sep 17 00:00:00 2001 From: Michael Beck Date: Wed, 21 Jun 2006 17:46:15 +0000 Subject: [PATCH] make sure a '\0' is at the end of an snprintf'ed string --- ir/be/benode.c | 1 + ir/be/beraextern.c | 1 + ir/be/bespill.c | 2 ++ ir/be/beutil.c | 1 + ir/be/beutil.h | 1 + 5 files changed, 6 insertions(+) diff --git a/ir/be/benode.c b/ir/be/benode.c index 5bad46892..3cc8b4239 100644 --- a/ir/be/benode.c +++ b/ir/be/benode.c @@ -1317,6 +1317,7 @@ static void dump_node_req(FILE *f, int idx, be_req_t *req) const char *prefix = buf; snprintf(buf, sizeof(buf), "#%d ", idx); + buf[sizeof(buf) - 1] = '\0'; if(req->flags != arch_irn_flags_none) { fprintf(f, "%sflags: ", prefix); diff --git a/ir/be/beraextern.c b/ir/be/beraextern.c index 2bf3a004d..f0dd30490 100644 --- a/ir/be/beraextern.c +++ b/ir/be/beraextern.c @@ -475,6 +475,7 @@ static void execute(char *prog_to_call, char *out_file, char *result_file) { int ret_status; snprintf(cmd_line, sizeof(cmd_line), "%s -i %s -o %s", prog_to_call, out_file, result_file); + cmd_line[sizeof(cmd_line) - 1] = '\0'; ret_status = system(cmd_line); assert(ret_status != -1 && "Invokation of external register allocator failed"); diff --git a/ir/be/bespill.c b/ir/be/bespill.c index aabdbfec2..94c22c97e 100644 --- a/ir/be/bespill.c +++ b/ir/be/bespill.c @@ -799,6 +799,7 @@ static ir_type *get_spill_type(pmap *types, spill_slot_t *ss) { if (! e) { char buf[64]; snprintf(buf, sizeof(buf), "spill_slot_type_%s", get_mode_name(ss->largest_mode)); + buf[sizeof(buf) - 1] = '\0'; res = new_type_primitive(new_id_from_str(buf), ss->largest_mode); set_type_alignment_bytes(res, ss->align); pmap_insert(types, ss->largest_mode, res); @@ -840,6 +841,7 @@ static void assign_entities(ss_env_t *ssenv, int n_slots, spill_slot_t *ss[]) { /* build entity */ snprintf(buf, sizeof(buf), "spill_slot_%d", i); + buf[sizeof(buf) - 1] = '\0'; name = new_id_from_str(buf); spill_ent = new_entity(frame, name, get_spill_type(ssenv->types, ss[i])); diff --git a/ir/be/beutil.c b/ir/be/beutil.c index 18effda0f..844fcf27f 100644 --- a/ir/be/beutil.c +++ b/ir/be/beutil.c @@ -182,6 +182,7 @@ void be_dump(ir_graph *irg, const char *suffix, void (*dumper)(ir_graph *, const } snprintf(buf, sizeof(buf), "-%02d%s", nr++, suffix); + buf[sizeof(buf) - 1] = '\0'; dumper(irg, buf); } diff --git a/ir/be/beutil.h b/ir/be/beutil.h index d1b1eb03a..ae193f5bb 100644 --- a/ir/be/beutil.h +++ b/ir/be/beutil.h @@ -87,6 +87,7 @@ static INLINE FILE *ffopen(const char *base, const char *ext, const char *mode) char buf[1024]; snprintf(buf, sizeof(buf), "%s.%s", base, ext); + buf[sizeof(buf) - 1] = '\0'; if (! (out = fopen(buf, mode))) { fprintf(stderr, "Cannot open file %s in mode %s\n", buf, mode); return NULL; -- 2.20.1