Thorsten Glaser wrote, on 24 Jun 2023:
> 
> what’s the POSIX mode behaviour expected when scripts attempt to
> use overlong numbers in arguments e.g. to utilities (but possibly
> anywhere in XSH)?
> 
> Say a script has on a 64-bit system:
> 
> test 2 -lt 99999999999999999999
> 
> I found “1.1.2 Concepts Derived from the ISO C Standard” in XSH
> Introduction, but that just says it should be signed long.

XCU 1.1.2 relates to utilities that "perform complex data manipulation
using their own procedure and arithmetic languages".  So it applies to
shell arithmetic expansion, but isn't really relevant to simple
argument parsing by a utility.  For that, the relevant text is in XBD
12.1 Utility Argument Syntax, item 6.  This specifies ranges that must
be "syntactically recognized as numeric values" and then says "Ranges
greater than those listed here are allowed."

So the allowed behaviours are that either the utility syntactically
recognises the argument as a numeric value or it doesn't.

If it doesn't, then it must report this as a syntax error.
If it does, then its behaviour must be as described by the standard
for the value that was recognised.

> So, is it:
> 
> • application error (the script writer is at fault, and the shell
>   can do what it wants but should be consistent)
> 
> • unspecified behaviour (the shell can do as it wants but should
>   be consistent); I really hope not C-level UB
> 
> • the utility or shell must detect this, while parsing the argument
>   as number, erroring out
> 
> I’d hope for one of the first two because having wraparound semantics
> is one of the guarantees for script writers I have in mksh for shell
> arithmetics (not yet explicitly in the test(1) builtin).

It's somewhere between the second and third. It's unspecified whether
the utility will report an error, but if it doesn't then it has to
handle the value correctly, i.e. test 2 -lt 99999999999999999999 must
exit with status 0 or status >1; it must not exit with status 1.

-- 
Geoff Clare <g.cl...@opengroup.org>
The Open Group, Apex Plaza, Forbury Road, Reading, RG1 1AX, England

  • out-of-bounds numbers... Thorsten Glaser via austin-group-l at The Open Group
    • Re: out-of-bound... Geoff Clare via austin-group-l at The Open Group
      • Re: out-of-b... Thorsten Glaser via austin-group-l at The Open Group
        • Re: out-... Geoff Clare via austin-group-l at The Open Group
        • Re: out-... Robert Elz via austin-group-l at The Open Group
          • Re: ... Gabriel Ravier via austin-group-l at The Open Group
          • Re: ... Thorsten Glaser via austin-group-l at The Open Group

Reply via email to