some fixes for xml dumper / still buggy.
[libfirm] / ir / tv / strcalc.c
index b016fb3..8a2d9ed 100644 (file)
@@ -1285,6 +1285,7 @@ unsigned char sc_sub_bits(const void *value, int len, unsigned byte_ofs)
 
 /*
  * convert to a string
+ * XXX Doesn't check buffer bounds
  */
 const char *sc_print(const void *value, unsigned bits, enum base_t base)
 {
@@ -1304,8 +1305,8 @@ const char *sc_print(const void *value, unsigned bits, enum base_t base)
   char *pos;
   const char *digits = small_digits;
 
-  pos = output_buffer + BIT_PATTERN_SIZE;
-  *pos = '\0';
+  pos = output_buffer + BIT_PATTERN_SIZE ;
+  *(--pos) = '\0';
 
   /* special case */
   if (bits == 0) {
@@ -1436,8 +1437,8 @@ void init_strcalc(int precision_in_bytes)
     CALC_BUFFER_SIZE = (4 * precision_in_bytes);
     MAX_VALUE_SIZE   = (2 * precision_in_bytes);
 
-    calc_buffer = malloc(CALC_BUFFER_SIZE * sizeof(char));
-    output_buffer = malloc(BIT_PATTERN_SIZE * sizeof(char));
+    calc_buffer = malloc(CALC_BUFFER_SIZE+1 * sizeof(char));
+    output_buffer = malloc(BIT_PATTERN_SIZE+1 * sizeof(char));
 
     if (calc_buffer == NULL || output_buffer == NULL)
     {