Skip to content

Commit 7c0876c

Browse files
committed
Fixup sys._getframe
1 parent 4a58e68 commit 7c0876c

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

Python/sysmodule.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1776,10 +1776,15 @@ sys__getframe_impl(PyObject *module, int depth)
17761776
return NULL;
17771777
}
17781778

1779-
while (depth > 0 && frame != NULL) {
1780-
frame = frame->previous;
1781-
if (!frame->is_artificial) {
1782-
--depth;
1779+
if (frame != NULL) {
1780+
while (depth > 0) {
1781+
frame = frame->previous;
1782+
if (frame == NULL) {
1783+
break;
1784+
}
1785+
if (!frame->is_artificial) {
1786+
--depth;
1787+
}
17831788
}
17841789
}
17851790
if (frame == NULL) {

0 commit comments

Comments
 (0)