mirror of
git://git.code.sf.net/p/zsh/code
synced 2025-10-04 08:30:54 +02:00
30656: prevent SIGFPE in division by -1 by multiplying instead
This commit is contained in:
parent
1f5ef83f0f
commit
361e171672
2 changed files with 29 additions and 4 deletions
|
@ -1,3 +1,8 @@
|
||||||
|
2012-09-06 Peter Stephenson <p.w.stephenson@ntlworld.com>
|
||||||
|
|
||||||
|
* 30656: Src/math.c: treat dividing by -1 the same as
|
||||||
|
multiplying by it to get around SIGFPE.
|
||||||
|
|
||||||
2012-09-05 Peter Stephenson <pws@csr.com>
|
2012-09-05 Peter Stephenson <pws@csr.com>
|
||||||
|
|
||||||
* Jun T.: 30658: Completion/Unix/Command/_uniq: more options.
|
* Jun T.: 30658: Completion/Unix/Command/_uniq: more options.
|
||||||
|
@ -137,5 +142,5 @@
|
||||||
|
|
||||||
*****************************************************
|
*****************************************************
|
||||||
* This is used by the shell to define $ZSH_PATCHLEVEL
|
* This is used by the shell to define $ZSH_PATCHLEVEL
|
||||||
* $Revision: 1.5715 $
|
* $Revision: 1.5716 $
|
||||||
*****************************************************
|
*****************************************************
|
||||||
|
|
26
Src/math.c
26
Src/math.c
|
@ -1053,14 +1053,34 @@ op(int what)
|
||||||
return;
|
return;
|
||||||
if (c.type == MN_FLOAT)
|
if (c.type == MN_FLOAT)
|
||||||
c.u.d = a.u.d / b.u.d;
|
c.u.d = a.u.d / b.u.d;
|
||||||
else
|
else {
|
||||||
c.u.l = a.u.l / b.u.l;
|
/*
|
||||||
|
* Avoid exception when dividing the smallest
|
||||||
|
* negative integer by -1. Always treat it the
|
||||||
|
* same as multiplication. This still doesn't give
|
||||||
|
* numerically the right answer in two's complement,
|
||||||
|
* but treating both these in the same way seems
|
||||||
|
* reasonable.
|
||||||
|
*/
|
||||||
|
if (b.u.l == -1)
|
||||||
|
c.u.l = - a.u.l;
|
||||||
|
else
|
||||||
|
c.u.l = a.u.l / b.u.l;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case MOD:
|
case MOD:
|
||||||
case MODEQ:
|
case MODEQ:
|
||||||
if (!notzero(b))
|
if (!notzero(b))
|
||||||
return;
|
return;
|
||||||
c.u.l = a.u.l % b.u.l;
|
/*
|
||||||
|
* Avoid exception as above.
|
||||||
|
* Any integer mod -1 is the same as any integer mod 1
|
||||||
|
* i.e. zero.
|
||||||
|
*/
|
||||||
|
if (b.u.l == -1)
|
||||||
|
c.u.l = 0;
|
||||||
|
else
|
||||||
|
c.u.l = a.u.l % b.u.l;
|
||||||
break;
|
break;
|
||||||
case PLUS:
|
case PLUS:
|
||||||
case PLUSEQ:
|
case PLUSEQ:
|
||||||
|
|
Loading…
Reference in a new issue