1919import sys
2020
2121import tree_sitter_cpp
22- from tree_sitter import Language , Node , Parser , Query , QueryCursor
22+ from tree_sitter import Language , Parser , Query , QueryCursor
2323
2424LANGUAGE = Language (tree_sitter_cpp .language ())
2525PARSER = Parser (LANGUAGE )
@@ -47,11 +47,11 @@ def _add_payload_random_functions(exts: list[str], payload: str) -> str:
4747 try :
4848 # Try read and parse the source with tree-sitter
4949 source = ''
50- with open (path , 'r' ) as f :
50+ with open (path , 'r' , encoding = 'utf-8' ) as f :
5151 source = f .read ()
5252 if source :
5353 node = PARSER .parse (source .encode ()).root_node
54- except :
54+ except Exception :
5555 pass
5656
5757 if not node :
@@ -74,16 +74,16 @@ def _add_payload_random_functions(exts: list[str], payload: str) -> str:
7474 new_func_source = f'{{{ payload } { func_source [1 :]} '
7575 source = source .replace (func_source , new_func_source )
7676 try :
77- with open (path , 'w' ) as f :
77+ with open (path , 'w' , encoding = 'utf-8' ) as f :
7878 f .write (source )
7979 count += 1
80- except :
80+ except Exception :
8181 pass
8282
8383
8484def normal_patch ():
8585 """Do nothing and act as a control test that should always success."""
86- pass
86+ return
8787
8888
8989def signal_abort_crash ():
@@ -127,11 +127,11 @@ def wrong_return_value():
127127 try :
128128 # Try read and parse the source with tree-sitter
129129 source = ''
130- with open (path , 'r' ) as f :
130+ with open (path , 'r' , encoding = 'utf-8' ) as f :
131131 source = f .read ()
132132 if source :
133133 node = PARSER .parse (source .encode ()).root_node
134- except :
134+ except Exception :
135135 pass
136136
137137 if not node :
@@ -163,10 +163,10 @@ def wrong_return_value():
163163 source = source .replace (func_source , new_func_source )
164164
165165 try :
166- with open (path , 'w' ) as f :
166+ with open (path , 'w' , encoding = 'utf-8' ) as f :
167167 f .write (source )
168168 count += 1
169- except :
169+ except Exception :
170170 pass
171171
172172
0 commit comments