[2.7] bpo-33308: Fix a crash in the parser module when convert an ST object. (GH-6519) (GH-6532)
Converting with line_info=False and col_info=True crashed before.
(cherry picked from commit e5362eaa75a154c6e91c5b1c47719d0a0f5ca48b)
diff --git a/Modules/parsermodule.c b/Modules/parsermodule.c
index 7955542..fcc618d 100644
--- a/Modules/parsermodule.c
+++ b/Modules/parsermodule.c
@@ -121,10 +121,10 @@
if (result != NULL) {
(void) addelem(result, 0, PyInt_FromLong(TYPE(n)));
(void) addelem(result, 1, PyString_FromString(STR(n)));
- if (lineno == 1)
+ if (lineno)
(void) addelem(result, 2, PyInt_FromLong(n->n_lineno));
- if (col_offset == 1)
- (void) addelem(result, 3, PyInt_FromLong(n->n_col_offset));
+ if (col_offset)
+ (void) addelem(result, 2 + lineno, PyInt_FromLong(n->n_col_offset));
}
return (result);
}