@@ -673,6 +673,8 @@ handle_keywordonly_args(struct compiling *c, const node *n, int start,
673673 case tfpdef :
674674 if (i + 1 < NCH (n ) && TYPE (CHILD (n , i + 1 )) == EQUAL ) {
675675 expression = ast_for_expr (c , CHILD (n , i + 2 ));
676+ if (!expression )
677+ goto error ;
676678 asdl_seq_SET (kwdefaults , j , expression );
677679 i += 2 ; /* '=' and test */
678680 }
@@ -682,10 +684,8 @@ handle_keywordonly_args(struct compiling *c, const node *n, int start,
682684 if (NCH (ch ) == 3 ) {
683685 /* ch is NAME ':' test */
684686 annotation = ast_for_expr (c , CHILD (ch , 2 ));
685- if (!annotation ) {
686- ast_error (ch , "expected expression" );
687+ if (!annotation )
687688 goto error ;
688- }
689689 }
690690 else {
691691 annotation = NULL ;
@@ -777,22 +777,22 @@ ast_for_arguments(struct compiling *c, const node *n)
777777 }
778778 posargs = (nposargs ? asdl_seq_new (nposargs , c -> c_arena ) : NULL );
779779 if (!posargs && nposargs )
780- goto error ;
780+ return NULL ;
781781 kwonlyargs = (nkwonlyargs ?
782782 asdl_seq_new (nkwonlyargs , c -> c_arena ) : NULL );
783783 if (!kwonlyargs && nkwonlyargs )
784- goto error ;
784+ return NULL ;
785785 posdefaults = (nposdefaults ?
786786 asdl_seq_new (nposdefaults , c -> c_arena ) : NULL );
787787 if (!posdefaults && nposdefaults )
788- goto error ;
788+ return NULL ;
789789 /* The length of kwonlyargs and kwdefaults are same
790790 since we set NULL as default for keyword only argument w/o default
791791 - we have sequence data structure, but no dictionary */
792792 kwdefaults = (nkwonlyargs ?
793793 asdl_seq_new (nkwonlyargs , c -> c_arena ) : NULL );
794794 if (!kwdefaults && nkwonlyargs )
795- goto error ;
795+ return NULL ;
796796
797797 if (nposargs + nkwonlyargs > 255 ) {
798798 ast_error (n , "more than 255 arguments" );
@@ -816,7 +816,7 @@ ast_for_arguments(struct compiling *c, const node *n)
816816 if (i + 1 < NCH (n ) && TYPE (CHILD (n , i + 1 )) == EQUAL ) {
817817 expr_ty expression = ast_for_expr (c , CHILD (n , i + 2 ));
818818 if (!expression )
819- goto error ;
819+ return NULL ;
820820 assert (posdefaults != NULL );
821821 asdl_seq_SET (posdefaults , j ++ , expression );
822822 i += 2 ;
@@ -825,27 +825,27 @@ ast_for_arguments(struct compiling *c, const node *n)
825825 else if (found_default ) {
826826 ast_error (n ,
827827 "non-default argument follows default argument" );
828- goto error ;
828+ return NULL ;
829829 }
830830 arg = compiler_arg (c , ch );
831831 if (!arg )
832- goto error ;
832+ return NULL ;
833833 asdl_seq_SET (posargs , k ++ , arg );
834834 i += 2 ; /* the name and the comma */
835835 break ;
836836 case STAR :
837837 if (i + 1 >= NCH (n )) {
838838 ast_error (CHILD (n , i ),
839839 "named arguments must follow bare *" );
840- goto error ;
840+ return NULL ;
841841 }
842842 ch = CHILD (n , i + 1 ); /* tfpdef or COMMA */
843843 if (TYPE (ch ) == COMMA ) {
844844 int res = 0 ;
845845 i += 2 ; /* now follows keyword only arguments */
846846 res = handle_keywordonly_args (c , n , i ,
847847 kwonlyargs , kwdefaults );
848- if (res == -1 ) goto error ;
848+ if (res == -1 ) return NULL ;
849849 i = res ; /* res has new position to process */
850850 }
851851 else {
@@ -855,14 +855,16 @@ ast_for_arguments(struct compiling *c, const node *n)
855855 if (NCH (ch ) > 1 ) {
856856 /* there is an annotation on the vararg */
857857 varargannotation = ast_for_expr (c , CHILD (ch , 2 ));
858+ if (!varargannotation )
859+ return NULL ;
858860 }
859861 i += 3 ;
860862 if (i < NCH (n ) && (TYPE (CHILD (n , i )) == tfpdef
861863 || TYPE (CHILD (n , i )) == vfpdef )) {
862864 int res = 0 ;
863865 res = handle_keywordonly_args (c , n , i ,
864866 kwonlyargs , kwdefaults );
865- if (res == -1 ) goto error ;
867+ if (res == -1 ) return NULL ;
866868 i = res ; /* res has new position to process */
867869 }
868870 }
@@ -874,24 +876,22 @@ ast_for_arguments(struct compiling *c, const node *n)
874876 if (NCH (ch ) > 1 ) {
875877 /* there is an annotation on the kwarg */
876878 kwargannotation = ast_for_expr (c , CHILD (ch , 2 ));
879+ if (!kwargannotation )
880+ return NULL ;
877881 }
878882 if (!kwarg )
879- goto error ;
883+ return NULL ;
880884 i += 3 ;
881885 break ;
882886 default :
883887 PyErr_Format (PyExc_SystemError ,
884888 "unexpected node in varargslist: %d @ %d" ,
885889 TYPE (ch ), i );
886- goto error ;
890+ return NULL ;
887891 }
888892 }
889893 return arguments (posargs , vararg , varargannotation , kwonlyargs , kwarg ,
890894 kwargannotation , posdefaults , kwdefaults , c -> c_arena );
891- error :
892- Py_XDECREF (vararg );
893- Py_XDECREF (kwarg );
894- return NULL ;
895895}
896896
897897static expr_ty
@@ -976,9 +976,9 @@ ast_for_decorators(struct compiling *c, const node *n)
976976
977977 for (i = 0 ; i < NCH (n ); i ++ ) {
978978 d = ast_for_decorator (c , CHILD (n , i ));
979- if (!d )
980- return NULL ;
981- asdl_seq_SET (decorator_seq , i , d );
979+ if (!d )
980+ return NULL ;
981+ asdl_seq_SET (decorator_seq , i , d );
982982 }
983983 return decorator_seq ;
984984}
@@ -1004,7 +1004,7 @@ ast_for_funcdef(struct compiling *c, const node *n, asdl_seq *decorator_seq)
10041004 if (TYPE (CHILD (n , name_i + 2 )) == RARROW ) {
10051005 returns = ast_for_expr (c , CHILD (n , name_i + 3 ));
10061006 if (!returns )
1007- return NULL ;
1007+ return NULL ;
10081008 name_i += 2 ;
10091009 }
10101010 body = ast_for_suite (c , CHILD (n , name_i + 3 ));
@@ -2152,11 +2152,10 @@ ast_for_expr_stmt(struct compiling *c, const node *n)
21522152 return NULL ;
21532153 }
21542154 e = ast_for_testlist (c , ch );
2155-
2156- /* set context to assign */
21572155 if (!e )
21582156 return NULL ;
21592157
2158+ /* set context to assign */
21602159 if (!set_context (c , e , Store , CHILD (n , i )))
21612160 return NULL ;
21622161
@@ -2957,6 +2956,8 @@ ast_for_with_item(struct compiling *c, const node *n, asdl_seq *content)
29572956
29582957 REQ (n , with_item );
29592958 context_expr = ast_for_expr (c , CHILD (n , 0 ));
2959+ if (!context_expr )
2960+ return NULL ;
29602961 if (NCH (n ) == 3 ) {
29612962 optional_vars = ast_for_expr (c , CHILD (n , 2 ));
29622963
0 commit comments