X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fdata%2Fdata-out.c;h=1ed83bcbc9b3f1221634600ae89c30505fee3cda;hb=068a4cbf264102f4ede4c3805eecbacf15f0f2d8;hp=a30e7e703838a31bab2ca5b4eba1b7ecff1899f3;hpb=c41cd1fefc98bb4abed33754276d93db9ffe2e0e;p=pspp-builds.git diff --git a/src/data/data-out.c b/src/data/data-out.c index a30e7e70..1ed83bcb 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); @@ -214,11 +215,9 @@ output_Z (const union value *input, const struct fmt_spec *format, char buf[128]; if (input->f == SYSMIS) output_missing (format, output); - else if (fabs (number) >= power10 (format->w) - || sprintf (buf, "%0*.0f", format->w, - fabs (round (number))) != format->w) - output_overflow (format, output); - else + else if (fabs (number) < power10 (format->w) + && sprintf (buf, "%0*.0f", format->w, + fabs (round (number))) == format->w) { if (number < 0 && strspn (buf, "0") < format->w) { @@ -228,6 +227,8 @@ output_Z (const union value *input, const struct fmt_spec *format, memcpy (output, buf, format->w); output[format->w] = '\0'; } + else + output_overflow (format, output); } /* Outputs P format. */ @@ -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; }