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=85e8eaae3a0288b1d32af2798798c527995db63a;hpb=6bf6119d76b761cbbca0ca9e5b680f419eaf937b;p=pspp-builds.git diff --git a/src/data/data-out.c b/src/data/data-out.c index 85e8eaae..bb774374 100644 --- a/src/data/data-out.c +++ b/src/data/data-out.c @@ -131,10 +131,13 @@ char * data_out_pool (const union value *input, const char *encoding, const struct fmt_spec *format, struct pool *pool) { - char *output = xmalloc (format->w + 1); + const struct fmt_number_style *style = settings_get_style (format->type); + char *output; char *t ; assert (fmt_check_output (format)); + output = xmalloc (format->w + style->extra_bytes + 1); + converters[format->type] (input, format, output); t = recode_string_pool (UTF8, encoding, output, format->w, pool); @@ -600,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 += ss_length (style->neg_suffix); + width += style->neg_suffix.width; if (add_neg_prefix) - width += ss_length (style->neg_prefix); + width += style->neg_prefix.width; if (width > format->w) continue; @@ -632,10 +635,9 @@ output_decimal (const struct rounder *r, const struct fmt_spec *format, if (format->w > width) p = mempset (p, ' ', format->w - width); if (add_neg_prefix) - p = mempcpy (p, ss_data (style->neg_prefix), - ss_length (style->neg_prefix)); + p = stpcpy (p, style->neg_prefix.s); if (add_affixes) - p = mempcpy (p, ss_data (style->prefix), ss_length (style->prefix)); + p = stpcpy (p, style->prefix.s); if (!add_grouping) p = mempcpy (p, magnitude, integer_digits); else @@ -654,13 +656,15 @@ output_decimal (const struct rounder *r, const struct fmt_spec *format, p = mempcpy (p, &magnitude[integer_digits + 1], decimals); } if (add_affixes) - p = mempcpy (p, ss_data (style->suffix), ss_length (style->suffix)); + p = stpcpy (p, style->suffix.s); if (add_neg_prefix) - p = mempcpy (p, ss_data (style->neg_suffix), - ss_length (style->neg_suffix)); + p = stpcpy (p, style->neg_suffix.s); else - p = mempset (p, ' ', ss_length (style->neg_suffix)); - 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 + ss_length (style->neg_suffix); + width = 6 + style->neg_suffix.width; if (number < 0) - width += ss_length (style->neg_prefix); + width += style->neg_prefix.width; if (width > format->w) return false; @@ -706,10 +710,9 @@ output_scientific (double number, const struct fmt_spec *format, if (width < format->w) p = mempset (p, ' ', format->w - width); if (number < 0) - p = mempcpy (p, ss_data (style->neg_prefix), - ss_length (style->neg_prefix)); + p = stpcpy (p, style->neg_prefix.s); if (add_affixes) - p = mempcpy (p, ss_data (style->prefix), ss_length (style->prefix)); + p = stpcpy (p, style->prefix.s); if (fraction_width > 0) sprintf (p, "%#.*E", fraction_width - 1, fabs (number)); else @@ -736,16 +739,15 @@ output_scientific (double number, const struct fmt_spec *format, /* Add suffixes. */ p = strchr (p, '\0'); if (add_affixes) - p = mempcpy (p, ss_data (style->suffix), ss_length (style->suffix)); + p = stpcpy (p, style->suffix.s); if (number < 0) - p = mempcpy (p, ss_data (style->neg_suffix), - ss_length (style->neg_suffix)); + p = stpcpy (p, style->neg_suffix.s); else - p = mempset (p, ' ', ss_length (style->neg_suffix)); + 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; }