summaryrefslogtreecommitdiff
path: root/Python/errors.c
diff options
context:
space:
mode:
Diffstat (limited to 'Python/errors.c')
-rw-r--r--Python/errors.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/Python/errors.c b/Python/errors.c
index cc00ae4a54..720f18bc22 100644
--- a/Python/errors.c
+++ b/Python/errors.c
@@ -1646,16 +1646,18 @@ err_programtext(PyThreadState *tstate, FILE *fp, int lineno)
{
int i;
char linebuf[1000];
-
- if (fp == NULL)
+ if (fp == NULL) {
return NULL;
+ }
+
for (i = 0; i < lineno; i++) {
char *pLastChar = &linebuf[sizeof(linebuf) - 2];
do {
*pLastChar = '\0';
if (Py_UniversalNewlineFgets(linebuf, sizeof linebuf,
- fp, NULL) == NULL)
- break;
+ fp, NULL) == NULL) {
+ goto after_loop;
+ }
/* fgets read *something*; if it didn't get as
far as pLastChar, it must have found a newline
or hit the end of the file; if pLastChar is \n,
@@ -1663,6 +1665,8 @@ err_programtext(PyThreadState *tstate, FILE *fp, int lineno)
yet seen a newline, so must continue */
} while (*pLastChar != '\0' && *pLastChar != '\n');
}
+
+after_loop:
fclose(fp);
if (i == lineno) {
PyObject *res;