summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1996-12-06 20:14:43 (GMT)
committerGuido van Rossum <guido@python.org>1996-12-06 20:14:43 (GMT)
commit9478dd40c2fd2ca41b7ad50a03546890591777bd (patch)
treeef30e81ca02d311293c4d2c3dd82ed980eaa2ffd
parentd560605ae61d05d663e51c789f868bc1def8fa58 (diff)
downloadcpython-9478dd40c2fd2ca41b7ad50a03546890591777bd.zip
cpython-9478dd40c2fd2ca41b7ad50a03546890591777bd.tar.gz
cpython-9478dd40c2fd2ca41b7ad50a03546890591777bd.tar.bz2
Fix core dump from pow(x,y,0).
Make gcc -Wall happy.
-rw-r--r--Objects/intobject.c16
1 files changed, 9 insertions, 7 deletions
diff --git a/Objects/intobject.c b/Objects/intobject.c
index e1ad157..6264920 100644
--- a/Objects/intobject.c
+++ b/Objects/intobject.c
@@ -342,7 +342,7 @@ int_mul(v, w)
b = -b;
if (b < 0) {
/* Largest negative */
- if (a == 0 || a == 1 && s == 1) {
+ if (a == 0 || (a == 1 && s == 1)) {
x = a*b;
goto ok;
}
@@ -427,7 +427,7 @@ i_divmod(x, y, p_xdivy, p_xmody)
xdivy = xi / yi;
}
xmody = xi - xdivy*yi;
- if (xmody < 0 && yi > 0 || xmody > 0 && yi < 0) {
+ if ((xmody < 0 && yi > 0) || (xmody > 0 && yi < 0)) {
xmody += yi;
xdivy -= 1;
}
@@ -476,8 +476,7 @@ int_pow(v, w, z)
intobject *z;
{
#if 1
- register long iv, iw, iz, ix, temp, prev;
- int zset = 0;
+ register long iv, iw, iz=0, ix, temp, prev;
iv = v->ob_ival;
iw = w->ob_ival;
if (iw < 0) {
@@ -486,7 +485,10 @@ int_pow(v, w, z)
}
if ((object *)z != None) {
iz = z->ob_ival;
- zset = 1;
+ if (iz == 0) {
+ err_setstr(ValueError, "pow(x, y, z) with z==0");
+ return NULL;
+ }
}
/*
* XXX: The original exponentiation code stopped looping
@@ -513,13 +515,13 @@ int_pow(v, w, z)
temp *= temp; /* Square the value of temp */
if (prev!=0 && temp/prev!=prev)
return err_ovf("integer pow()");
- if (zset) {
+ if (iz) {
/* If we did a multiplication, perform a modulo */
ix = ix % iz;
temp = temp % iz;
}
}
- if (zset) {
+ if (iz) {
object *t1, *t2;
long int div, mod;
t1=newintobject(ix);