Skip to content

Commit d7528ec

Browse files
committed
pylint/mypy: Fix pylint/mypy errors for frontends
Signed-off-by: Arthur Chan <[email protected]>
1 parent 1a5b10f commit d7528ec

File tree

5 files changed

+30
-21
lines changed

5 files changed

+30
-21
lines changed

src/fuzz_introspector/frontends/datatypes.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,9 @@ def get_function_by_source_suffix_line(self, target_source_file,
198198
for function in self.all_functions:
199199
source_file = function.parent_source.source_file
200200
if source_file.endswith(target_source_file):
201-
if function.start_line <= target_source_line <= function.end_line:
201+
start_line = function.start_line
202+
end_line = function.end_line
203+
if start_line <= target_source_line <= end_line:
202204
return function
203205

204206
return None

src/fuzz_introspector/frontends/frontend_c.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ def generate_report(self,
6666

6767
for func_def in source_code.func_defs:
6868
if harness_source:
69-
if func_def.name(
70-
) == 'LLVMFuzzerTestOneInput' and source_code.source_file != harness_source:
69+
if (func_def.name() == 'LLVMFuzzerTestOneInput'
70+
and source_code.source_file != harness_source):
7171
logger.debug('Skipping harness: %s -- %s -- %s',
7272
func_def.name(), source_code.source_file,
7373
harness_source)
@@ -265,8 +265,8 @@ def name(self):
265265
name_node = self.root
266266
while name_node.child_by_field_name('declarator') is not None:
267267
name_node = name_node.child_by_field_name('declarator')
268-
# Assign function name here because we want to make sure that there is a
269-
# declarator when defining the name.
268+
# Assign function name here because we want to make sure that
269+
# there is a declarator when defining the name.
270270
function_name = name_node.text.decode()
271271
return function_name
272272

@@ -431,8 +431,8 @@ def detailed_callsites(self):
431431
for call_child in call_expr.children:
432432
if call_child.type == 'identifier':
433433
src_line = call_child.start_point.row
434-
src_loc = self.parent_source.source_file + ':%d,1' % (
435-
src_line)
434+
src_loc = (f'{self.parent_source.source_file}:'
435+
f'{src_line},1')
436436
callsites.append({
437437
'Src': src_loc,
438438
'Dst': call_child.text.decode()
@@ -617,7 +617,7 @@ def get_linenumber(self, bytepos):
617617

618618
lineno = 1
619619
for start, end in self.line_range_pairs:
620-
if bytepos >= start and bytepos <= end:
620+
if start <= bytepos <= end:
621621
return lineno
622622
lineno += 1
623623

@@ -626,7 +626,8 @@ def get_linenumber(self, bytepos):
626626

627627
def load_treesitter_trees(source_files: list[str],
628628
is_log: bool = True) -> CProject:
629-
"""Creates treesitter trees for all files in a given list of source files."""
629+
"""Creates treesitter trees for all files in a given list of
630+
source files."""
630631
results = []
631632

632633
for code_file in source_files:

src/fuzz_introspector/frontends/frontend_go.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -740,7 +740,7 @@ def extract_local_variable_type(self,
740740
continue
741741

742742
decl_type = self.var_map.get(right.text.decode(), '')
743-
if '[' in decl_type and ']' in decl_type:
743+
if decl_type and '[' in decl_type and ']' in decl_type:
744744
decl_type = decl_type.split(']', 1)[-1]
745745
elif decl_type == 'string':
746746
decl_type = 'uint8'

src/fuzz_introspector/frontends/frontend_jvm.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -635,6 +635,7 @@ def _process_invoke(
635635
is_constructor_call: bool = False
636636
) -> tuple[str, list[tuple[str, int, int]]]:
637637
"""Internal helper for processing the method invocation statement."""
638+
return_type = ''
638639
callsites = []
639640

640641
# JVM method_invocation separated into three main items

src/fuzz_introspector/frontends/oss_fuzz.py

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,14 @@
1313
# limitations under the License.
1414
#
1515
################################################################################
16+
"""Entrypoint for tree-sitter frontends."""
1617

1718
import os
1819
import yaml
1920
import pathlib
2021
import logging
2122

22-
from typing import Tuple, Any
23+
from typing import Any, Optional
2324

2425
from fuzz_introspector.frontends import frontend_c
2526
from fuzz_introspector.frontends import frontend_cpp
@@ -108,7 +109,7 @@ def process_c_project(target_dir: str,
108109
logger.info('Extracting calltree for %s', harness.source_file)
109110
calltree = project.extract_calltree(source_code=harness,
110111
function=entrypoint)
111-
with open(os.path.join(out, 'fuzzerLogFile-%d.data' % (idx)),
112+
with open(os.path.join(out, f'fuzzerLogFile-{idx}.data'),
112113
'w',
113114
encoding='utf-8') as f:
114115
f.write("Call tree\n")
@@ -118,15 +119,19 @@ def process_c_project(target_dir: str,
118119
return project
119120

120121

121-
def analyse_folder(language: str = '',
122-
directory: str = '',
123-
entrypoint: str = '',
124-
out='',
125-
module_only=False,
126-
dump_output=True,
127-
files_to_include: list[str] = []) -> Tuple[Project, Any]:
122+
def analyse_folder(
123+
language: str = '',
124+
directory: str = '',
125+
entrypoint: str = '',
126+
out='',
127+
module_only=False,
128+
dump_output=True,
129+
files_to_include: Optional[list[str]] = None) -> tuple[Project, Any]:
128130
"""Runs a full frontend analysis on a given directory"""
129131

132+
if not files_to_include:
133+
files_to_include = []
134+
130135
# Extract source files for target language
131136
source_files = capture_source_files_in_tree(directory, language)
132137
source_files.extend(files_to_include)
@@ -206,7 +211,7 @@ def analyse_folder(language: str = '',
206211
harness_name = harness.source_file.split('/')[-1].split('.')[0]
207212

208213
# Functions/Methods data
209-
logger.info(f'Dump methods for {harness_name}')
214+
logger.info('Dump methods for %s', harness_name)
210215
target = os.path.join(out,
211216
f'fuzzerLogFile-{harness_name}.data.yaml')
212217
project.dump_module_logic(target,
@@ -216,7 +221,7 @@ def analyse_folder(language: str = '',
216221
dump_output=dump_output)
217222

218223
# Calltree
219-
logger.info(f'Extracting calltree for {harness_name}')
224+
logger.info('Extracting calltree for %s', harness_name)
220225
calltree = project.extract_calltree(harness.source_file, harness,
221226
entry_function)
222227
if dump_output:

0 commit comments

Comments
 (0)