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

Re: SIGFPE crash



On Sat, May 7, 2011 at 3:17 PM, Mikael Magnusson <mikachu@xxxxxxxxx> wrote:
> On 7 May 2011 23:56, Jon Mayo <jon.mayo@xxxxxxxxx> wrote:
>> echo $[-9223372036854775808/-1]
>>
>> this causes zsh to exit immediately with an FPE. Does anyone have a
>> patch to fix this?
>
> diff --git a/Src/math.c b/Src/math.c
> index 35b362d..3c08052 100644
> --- a/Src/math.c
> +++ b/Src/math.c
> @@ -1053,8 +1053,12 @@ op(int what)
>                    return;
>                if (c.type == MN_FLOAT)
>                    c.u.d = a.u.d / b.u.d;
> -               else
> -                   c.u.l = a.u.l / b.u.l;
> +               else {
> +                    if (a.u.l == LONG_MIN && b.u.l == -1)

should be LLONG_MIN

> +                        c.u.l = 0;

LLONG_MAX would be the closest answer, but 1 off. I would switch it
from integer to double type in this case, but that might be difficult.

> +                    else
> +                       c.u.l = a.u.l / b.u.l;
> +                }
>                break;
>            case MOD:
>            case MODEQ:
>
>
> Do we want to print a warning and/or use another value than 0 in this case?
>
> --
> Mikael Magnusson
>

-- Jon


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