X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fdata%2Fdata-out.c;h=bb774374d476cbc7b6c04aa0db60c7ecc452fc04;hb=4e8257086ffc71bc5a1785fd86610921be677887;hp=a30e7e703838a31bab2ca5b4eba1b7ecff1899f3;hpb=c41cd1fefc98bb4abed33754276d93db9ffe2e0e;p=pspp-builds.git diff --git a/src/data/data-out.c b/src/data/data-out.c index a30e7e70..bb774374 100644 --- a/src/data/data-out.c +++ b/src/data/data-out.c @@ -131,11 +131,12 @@ char * data_out_pool (const union value *input, const char *encoding, const struct fmt_spec *format, struct pool *pool) { + const struct fmt_number_style *style = settings_get_style (format->type); char *output; char *t ; assert (fmt_check_output (format)); - output = xmalloc (format->w + 1); + output = xmalloc (format->w + style->extra_bytes + 1); converters[format->type] (input, format, output); @@ -602,9 +603,9 @@ output_decimal (const struct rounder *r, const struct fmt_spec *format, the negative suffix, plus (if negative) the negative prefix. */ width = rounder_width (r, decimals, &integer_digits, &add_neg_prefix); - width += strlen (style->neg_suffix.s); + width += style->neg_suffix.width; if (add_neg_prefix) - width += strlen (style->neg_prefix.s); + width += style->neg_prefix.width; if (width > format->w) continue; @@ -659,8 +660,11 @@ output_decimal (const struct rounder *r, const struct fmt_spec *format, if (add_neg_prefix) p = stpcpy (p, style->neg_suffix.s); else - p = mempset (p, ' ', strlen (style->neg_suffix.s)); - assert (p == output + format->w); + p = mempset (p, ' ', style->neg_suffix.width); + + assert (p >= output + format->w); + assert (p <= output + format->w + style->extra_bytes); + *p = '\0'; return true; } @@ -681,9 +685,9 @@ output_scientific (double number, const struct fmt_spec *format, char buf[64], *p; /* Allocate minimum required space. */ - width = 6 + strlen (style->neg_suffix.s); + width = 6 + style->neg_suffix.width; if (number < 0) - width += strlen (style->neg_prefix.s); + width += style->neg_prefix.width; if (width > format->w) return false; @@ -739,11 +743,11 @@ output_scientific (double number, const struct fmt_spec *format, if (number < 0) p = stpcpy (p, style->neg_suffix.s); else - p = mempset (p, ' ', strlen (style->neg_suffix.s)); + p = mempset (p, ' ', style->neg_suffix.width); - assert (p == buf + format->w); - memcpy (output, buf, format->w); - output[format->w] = '\0'; + assert (p >= output + format->w); + assert (p <= output + format->w + style->extra_bytes); + *p = '\0'; return true; }