summaryrefslogtreecommitdiff
path: root/pp.c
diff options
context:
space:
mode:
Diffstat (limited to 'pp.c')
-rw-r--r--pp.c27
1 files changed, 21 insertions, 6 deletions
diff --git a/pp.c b/pp.c
index 4080c45296..f9f9e7b82d 100644
--- a/pp.c
+++ b/pp.c
@@ -2433,9 +2433,12 @@ PP(pp_i_divide)
if (value == 0)
DIE(aTHX_ "Illegal division by zero");
num = POPi;
- if (num == IV_MIN && value == -1)
- DIE(aTHX_ "Integer overflow in division");
- value = num / value;
+
+ /* avoid FPE_INTOVF on some platforms when num is IV_MIN */
+ if (value == -1)
+ value = - num;
+ else
+ value = num / value;
PUSHi( value );
RETURN;
}
@@ -2450,7 +2453,11 @@ PP(pp_i_modulo_0)
dPOPTOPiirl;
if (!right)
DIE(aTHX_ "Illegal modulus zero");
- SETi( left % right );
+ /* avoid FPE_INTOVF on some platforms when left is IV_MIN */
+ if (right == -1)
+ SETi( 0 );
+ else
+ SETi( left % right );
RETURN;
}
}
@@ -2467,7 +2474,11 @@ PP(pp_i_modulo_1)
dPOPTOPiirl;
if (!right)
DIE(aTHX_ "Illegal modulus zero");
- SETi( left % PERL_ABS(right) );
+ /* avoid FPE_INTOVF on some platforms when left is IV_MIN */
+ if (right == -1)
+ SETi( 0 );
+ else
+ SETi( left % PERL_ABS(right) );
RETURN;
}
}
@@ -2508,7 +2519,11 @@ PP(pp_i_modulo)
}
}
#endif
- SETi( left % right );
+ /* avoid FPE_INTOVF on some platforms when left is IV_MIN */
+ if (right == -1)
+ SETi( 0 );
+ else
+ SETi( left % right );
RETURN;
}
}