summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPádraig Brady <P@draigBrady.com>2012-11-23 03:06:07 +0000
committerPádraig Brady <P@draigBrady.com>2012-11-24 15:25:19 +0000
commit64d4a2807d46a85cfe5ab7eb99b3e91b9a75d5ab (patch)
treea6675c8ed665aba91591fd82029210b4fc18f7ce /src
parentce48a81bce089f703a12871f98ab1240c4c3554c (diff)
downloadcoreutils-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.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/seq.c b/src/seq.c
index e5788caab..9c2c51fbe 100644
--- a/src/seq.c
+++ b/src/seq.c
@@ -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;
}
}