Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d014ea6

Browse files
committed
* classobject.c: in instance_lenth, test result of call_object
for exception before using it. Fixed a few other places where the outcome of calling sq_length wasn't tested for exceptions (bltinmodule.c, ceval.c).
1 parent 18fc569 commit d014ea6

3 files changed

Lines changed: 6 additions & 0 deletions

File tree

Objects/classobject.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,8 @@ instance_length(inst)
324324
return -1;
325325
res = call_object(func, (object *)NULL);
326326
DECREF(func);
327+
if (res == NULL)
328+
return -1;
327329
if (is_intobject(res)) {
328330
outcome = getintvalue(res);
329331
if (outcome < 0)

Python/bltinmodule.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,8 @@ min_max(v, sign)
412412
return NULL;
413413
}
414414
n = (*sq->sq_length)(v);
415+
if (n < 0)
416+
return NULL;
415417
if (n == 0) {
416418
err_setstr(ValueError, "min() or max() of empty sequence");
417419
return NULL;

Python/ceval.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1881,6 +1881,8 @@ loop_subscript(v, w)
18811881
}
18821882
i = getintvalue(w);
18831883
n = (*sq->sq_length)(v);
1884+
if (n < 0)
1885+
return NULL; /* Exception */
18841886
if (i >= n)
18851887
return NULL; /* End of loop */
18861888
return (*sq->sq_item)(v, i);

0 commit comments

Comments
 (0)