@@ -741,6 +741,8 @@ static string
741
741
new_type_comment (const char * s , struct compiling * c )
742
742
{
743
743
PyObject * res = PyUnicode_DecodeUTF8 (s , strlen (s ), NULL );
744
+ if (!res )
745
+ return NULL ;
744
746
if (PyArena_AddPyObject (c -> c_arena , res ) < 0 ) {
745
747
Py_DECREF (res );
746
748
return NULL ;
@@ -1449,6 +1451,8 @@ handle_keywordonly_args(struct compiling *c, const node *n, int start,
1449
1451
case TYPE_COMMENT :
1450
1452
/* arg will be equal to the last argument processed */
1451
1453
arg -> type_comment = NEW_TYPE_COMMENT (ch );
1454
+ if (!arg -> type_comment )
1455
+ goto error ;
1452
1456
i += 1 ;
1453
1457
break ;
1454
1458
case DOUBLESTAR :
@@ -1618,6 +1622,8 @@ ast_for_arguments(struct compiling *c, const node *n)
1618
1622
1619
1623
if (i < NCH (n ) && TYPE (CHILD (n , i )) == TYPE_COMMENT ) {
1620
1624
vararg -> type_comment = NEW_TYPE_COMMENT (CHILD (n , i ));
1625
+ if (!vararg -> type_comment )
1626
+ return NULL ;
1621
1627
i += 1 ;
1622
1628
}
1623
1629
@@ -1649,6 +1655,8 @@ ast_for_arguments(struct compiling *c, const node *n)
1649
1655
1650
1656
/* arg will be equal to the last argument processed */
1651
1657
arg -> type_comment = NEW_TYPE_COMMENT (ch );
1658
+ if (!arg -> type_comment )
1659
+ return NULL ;
1652
1660
i += 1 ;
1653
1661
break ;
1654
1662
default :
@@ -1788,6 +1796,8 @@ ast_for_funcdef_impl(struct compiling *c, const node *n0,
1788
1796
}
1789
1797
if (TYPE (CHILD (n , name_i + 3 )) == TYPE_COMMENT ) {
1790
1798
type_comment = NEW_TYPE_COMMENT (CHILD (n , name_i + 3 ));
1799
+ if (!type_comment )
1800
+ return NULL ;
1791
1801
name_i += 1 ;
1792
1802
}
1793
1803
body = ast_for_suite (c , CHILD (n , name_i + 3 ));
@@ -1804,6 +1814,8 @@ ast_for_funcdef_impl(struct compiling *c, const node *n0,
1804
1814
return NULL ;
1805
1815
}
1806
1816
type_comment = NEW_TYPE_COMMENT (tc );
1817
+ if (!type_comment )
1818
+ return NULL ;
1807
1819
}
1808
1820
}
1809
1821
@@ -3290,8 +3302,11 @@ ast_for_expr_stmt(struct compiling *c, const node *n)
3290
3302
expression = ast_for_expr (c , value );
3291
3303
if (!expression )
3292
3304
return NULL ;
3293
- if (has_type_comment )
3305
+ if (has_type_comment ) {
3294
3306
type_comment = NEW_TYPE_COMMENT (CHILD (n , nch_minus_type ));
3307
+ if (!type_comment )
3308
+ return NULL ;
3309
+ }
3295
3310
else
3296
3311
type_comment = NULL ;
3297
3312
return Assign (targets , expression , type_comment , LINENO (n ), n -> n_col_offset , c -> c_arena );
@@ -3979,8 +3994,11 @@ ast_for_for_stmt(struct compiling *c, const node *n0, bool is_async)
3979
3994
if (!suite_seq )
3980
3995
return NULL ;
3981
3996
3982
- if (has_type_comment )
3997
+ if (has_type_comment ) {
3983
3998
type_comment = NEW_TYPE_COMMENT (CHILD (n , 5 ));
3999
+ if (!type_comment )
4000
+ return NULL ;
4001
+ }
3984
4002
else
3985
4003
type_comment = NULL ;
3986
4004
@@ -4171,8 +4189,11 @@ ast_for_with_stmt(struct compiling *c, const node *n0, bool is_async)
4171
4189
if (!body )
4172
4190
return NULL ;
4173
4191
4174
- if (has_type_comment )
4192
+ if (has_type_comment ) {
4175
4193
type_comment = NEW_TYPE_COMMENT (CHILD (n , NCH (n ) - 2 ));
4194
+ if (!type_comment )
4195
+ return NULL ;
4196
+ }
4176
4197
else
4177
4198
type_comment = NULL ;
4178
4199
0 commit comments