Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: SIGFPE crash



On 2011-05-08 00:27:30 +0200, Mikael Magnusson wrote:
> This is assuming we want to do this at all,

One should have a well-defined behavior.

> I am told that only division will generate an exception on x86, but
> presumably other arches behave differently,

Perhaps, but this also depends on the compiler. The operation
LONG_MIN/(-1) has an undefined behavior in two's complement
because the result is not representable. So, it should be avoided.

> and bash behaves the same way too (exception + die). Does some sort
> of standard have anything to say on the matter? I'm guessing someone
> has thought of it before and clearly nobody ever did anything about
> it.

It seems that POSIX just says:

  If the expression is invalid, the expansion fails and the shell
  shall write a message to standard error indicating the failure.

The behavior doesn't seem to be explicitly specified when there is
an overflow, and may be covered by an extension to provide a valid
result (e.g. using floating-point). Otherwise I suppose that the
behavior should not be worse than an invalid expression, e.g. a
crash shouldn't occur.

At least zsh should behave in a consistent way. For instance,
$((0/0)) returns an error, so that it should be the same case
with the minimum integer divided by -1.

-- 
Vincent Lefèvre <vincent@xxxxxxxxxx> - Web: <http://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <http://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / Arénaire project (LIP, ENS-Lyon)



Messages sorted by: Reverse Date, Date, Thread, Author