Instead, it either outputs correctly or diagnoses a too-large width.
[This bug was present in "the beginning".]
+ od +N. (where N is a decimal number) works again as per POSIX.
+ [bug introduced on 1995-01-25]
+
sort with key character offsets of SIZE_MAX, could induce
a read of 1 byte before an allocated heap buffer. For example:
'sort +0.18446744073709551615R input' on 64 bit systems.
leading '+' return true and set *OFFSET to the offset it denotes. */
static bool
-parse_old_offset (char const *s, uintmax_t *offset)
+parse_old_offset (char *s, uintmax_t *offset)
{
int radix;
++s;
/* Determine the radix we'll use to interpret S. If there is a '.',
+ optionally followed by 'B' or 'b' and then end of string,
it's decimal, otherwise, if the string begins with '0X'or '0x',
it's hexadecimal, else octal. */
- if (strchr (s, '.') != nullptr)
- radix = 10;
+ char *dot = strchr (s, '.');
+ if (dot)
+ {
+ bool b = dot[1] == 'B' || dot[1] == 'b';
+ if (dot[b + 1])
+ dot = nullptr;
+ }
+
+ if (dot)
+ {
+ /* Temporarily remove the '.' from the decimal string. */
+ dot[0] = dot[1];
+ dot[1] = '\0';
+ radix = 10;
+ }
else
{
if (s[0] == '0' && (s[1] == 'x' || s[1] == 'X'))
radix = 8;
}
- return xstrtoumax (s, nullptr, radix, offset, "Bb") == LONGINT_OK;
+ enum strtol_error s_err = xstrtoumax (s, nullptr, radix, offset, "Bb");
+
+ if (dot)
+ {
+ /* Restore the decimal string's original value. */
+ dot[1] = dot[0];
+ dot[0] = '.';
+ }
+
+ return s_err == LONGINT_OK;
}
/* Read a chunk of size BYTES_PER_BLOCK from the input files, write the
['j-proc', "-An -c -j $proc_file_byte_count $proc_file",
{IN=>{f2=>'e'}}, {OUT=>" e\n"}],
+ # Check that the traditional form '+N.' works, as per POSIX.
+ ['trad-dot1', '+1.', {IN_PIPE=>'a'}, {OUT=>"0000001\n"}],
+ ['trad-dot512', '+1.b', {IN_PIPE => 'a' x 512}, {OUT=>"0001000\n"}],
+
# Ensure that a large width does not cause trouble.
# From coreutils-7.0 through coreutils-8.21, these would print
# approximately 128KiB of padding.