From 9efd67537ac1e6ff6c7dec9f45c95c2cec8b80b0 Mon Sep 17 00:00:00 2001 From: Michael Beck Date: Wed, 21 Jun 2006 17:53:01 +0000 Subject: [PATCH] make sure a '\0' is at the end of an snprintf'ed string [r7954] --- ir/tv/fltcalc.c | 1 + ir/tv/tv.c | 9 +++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/ir/tv/fltcalc.c b/ir/tv/fltcalc.c index 7c5d6fdd1..761bf8362 100644 --- a/ir/tv/fltcalc.c +++ b/ir/tv/fltcalc.c @@ -1529,6 +1529,7 @@ char *fc_print(const void *a, char *buf, int buflen, unsigned base) case FC_PACKED: default: snprintf(buf, buflen, "%s", sc_print(_pack(val, mul_1), value_size*4, SC_HEX)); + buf[buflen - 1] = '\0'; break; } return buf; diff --git a/ir/tv/tv.c b/ir/tv/tv.c index 0e6a1720b..bb4eab12f 100644 --- a/ir/tv/tv.c +++ b/ir/tv/tv.c @@ -137,13 +137,13 @@ INLINE static void tarval_verify(tarval *tv) } #endif /* NDEBUG */ -static int hash_tv(tarval *tv) -{ +/** Hash a tarval. */ +static int hash_tv(tarval *tv) { return (PTR_TO_INT(tv->value) ^ PTR_TO_INT(tv->mode)) + tv->length; } -static int hash_val(const void *value, unsigned int length) -{ +/** Hash a value. Treat it as a byte array. */ +static int hash_val(const void *value, unsigned int length) { unsigned int i; unsigned int hash = 0; @@ -922,6 +922,7 @@ tarval *tarval_convert_to(tarval *src, ir_mode *m) * interpreted unsigned by fc_val_from_str, so this is a HACK */ snprintf(buffer, 100, "%s", sc_print(src->value, get_mode_size_bits(src->mode), SC_DEC)); + buffer[100 - 1] = '\0'; switch (get_mode_size_bits(m)) { case 32: -- 2.20.1