projects
/
pspp
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
format: Count prefix and suffix width in terms of display columns.
[pspp]
/
src
/
data
/
data-out.c
diff --git
a/src/data/data-out.c
b/src/data/data-out.c
index a30e7e703838a31bab2ca5b4eba1b7ecff1899f3..bb774374d476cbc7b6c04aa0db60c7ecc452fc04 100644
(file)
--- 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)
{
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));
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);
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);
the negative suffix, plus (if negative) the negative
prefix. */
width = rounder_width (r, decimals, &integer_digits, &add_neg_prefix);
- width += st
rlen (style->neg_suffix.s)
;
+ width += st
yle->neg_suffix.width
;
if (add_neg_prefix)
if (add_neg_prefix)
- width += st
rlen (style->neg_prefix.s)
;
+ width += st
yle->neg_prefix.width
;
if (width > format->w)
continue;
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
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;
}
return true;
}
@@
-681,9
+685,9
@@
output_scientific (double number, const struct fmt_spec *format,
char buf[64], *p;
/* Allocate minimum required space. */
char buf[64], *p;
/* Allocate minimum required space. */
- width = 6 + st
rlen (style->neg_suffix.s)
;
+ width = 6 + st
yle->neg_suffix.width
;
if (number < 0)
if (number < 0)
- width += st
rlen (style->neg_prefix.s)
;
+ width += st
yle->neg_prefix.width
;
if (width > format->w)
return false;
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
if (number < 0)
p = stpcpy (p, style->neg_suffix.s);
else
- p = mempset (p, ' ', st
rlen (style->neg_suffix.s)
);
+ p = mempset (p, ' ', st
yle->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;
}
return true;
}