make sure a '\0' is at the end of an snprintf'ed string
authorMichael Beck <beck@ipd.info.uni-karlsruhe.de>
Wed, 21 Jun 2006 17:46:15 +0000 (17:46 +0000)
committerMichael Beck <beck@ipd.info.uni-karlsruhe.de>
Wed, 21 Jun 2006 17:46:15 +0000 (17:46 +0000)
ir/be/benode.c
ir/be/beraextern.c
ir/be/bespill.c
ir/be/beutil.c
ir/be/beutil.h

index 5bad468..3cc8b42 100644 (file)
@@ -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);
index 2bf3a00..f0dd304 100644 (file)
@@ -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");
index aabdbfe..94c22c9 100644 (file)
@@ -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]));
index 18effda..844fcf2 100644 (file)
@@ -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);
 }
 
index d1b1eb0..ae193f5 100644 (file)
@@ -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;