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:53:01 +0000 (17:53 +0000)
committerMichael Beck <beck@ipd.info.uni-karlsruhe.de>
Wed, 21 Jun 2006 17:53:01 +0000 (17:53 +0000)
[r7954]

ir/tv/fltcalc.c
ir/tv/tv.c

index 7c5d6fd..761bf83 100644 (file)
@@ -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;
index 0e6a172..bb4eab1 100644 (file)
@@ -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: