diff options
author | Pádraig Brady <P@draigBrady.com> | 2012-11-23 03:06:07 +0000 |
---|---|---|
committer | Pádraig Brady <P@draigBrady.com> | 2012-11-24 15:25:19 +0000 |
commit | 64d4a2807d46a85cfe5ab7eb99b3e91b9a75d5ab (patch) | |
tree | a6675c8ed665aba91591fd82029210b4fc18f7ce /src | |
parent | ce48a81bce089f703a12871f98ab1240c4c3554c (diff) | |
download | coreutils-64d4a2807d46a85cfe5ab7eb99b3e91b9a75d5ab.tar.xz |
seq: ensure correct output width for scientific notation input
* src/seq.c (scan_arg): Calculate the width more accurately
for numbers specified using scientific notation.
* tests/misc/seq.pl: Add tests for cases that were mishandled.
* NEWS: Mention the fix.
* THANKS.in: Reported by Marcel Böhme.
Fixes http://bugs.gnu.org/12959
Diffstat (limited to 'src')
-rw-r--r-- | src/seq.c | 15 |
1 files changed, 15 insertions, 0 deletions
@@ -166,6 +166,21 @@ scan_arg (const char *arg) { long exponent = strtol (e + 1, NULL, 10); ret.precision += exponent < 0 ? -exponent : 0; + /* Don't account for e.... in the width since this is not output. */ + ret.width -= strlen (arg) - (e - arg); + /* Adjust the width as per the exponent. */ + if (exponent < 0) + { + if (decimal_point) + { + if (e == decimal_point + 1) /* undo #. -> # above */ + ret.width++; + } + else + ret.width++; + exponent = -exponent; + } + ret.width += exponent; } } |