@@ -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
@@ -3286,8 +3298,11 @@ ast_for_expr_stmt(struct compiling *c, const node *n)
3286
3298
expression = ast_for_expr (c , value );
3287
3299
if (!expression )
3288
3300
return NULL ;
3289
- if (has_type_comment )
3301
+ if (has_type_comment ) {
3290
3302
type_comment = NEW_TYPE_COMMENT (CHILD (n , nch_minus_type ));
3303
+ if (!type_comment )
3304
+ return NULL ;
3305
+ }
3291
3306
else
3292
3307
type_comment = NULL ;
3293
3308
return Assign (targets , expression , type_comment , LINENO (n ), n -> n_col_offset , c -> c_arena );
@@ -3975,8 +3990,11 @@ ast_for_for_stmt(struct compiling *c, const node *n0, bool is_async)
3975
3990
if (!suite_seq )
3976
3991
return NULL ;
3977
3992
3978
- if (has_type_comment )
3993
+ if (has_type_comment ) {
3979
3994
type_comment = NEW_TYPE_COMMENT (CHILD (n , 5 ));
3995
+ if (!type_comment )
3996
+ return NULL ;
3997
+ }
3980
3998
else
3981
3999
type_comment = NULL ;
3982
4000
@@ -4167,8 +4185,11 @@ ast_for_with_stmt(struct compiling *c, const node *n0, bool is_async)
4167
4185
if (!body )
4168
4186
return NULL ;
4169
4187
4170
- if (has_type_comment )
4188
+ if (has_type_comment ) {
4171
4189
type_comment = NEW_TYPE_COMMENT (CHILD (n , NCH (n ) - 2 ));
4190
+ if (!type_comment )
4191
+ return NULL ;
4192
+ }
4172
4193
else
4173
4194
type_comment = NULL ;
4174
4195
0 commit comments