Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix CodeQL warnings #51

Merged
merged 1 commit into from
Jul 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions amarna/command_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from amarna.Result import Result, ResultMultiplePositions, output_result
from amarna.Result import SARIF_MODE, SUMMARY_MODE
from typing import List, Union
import sys

example_usage = """---------------\nUsage examples\n---------------
Analyze a Cairo project in the current directory and export results to a file:
Expand Down Expand Up @@ -42,7 +43,7 @@ def get_rule_names(rules: str, excluded: str) -> List[str]:
for rule in rules + excluded:
if rule not in ALL_RULES:
print("Unknown rule: " + repr(rule))
exit(-1)
sys.exit(-1)

if rules:
base_rules = rules
Expand Down Expand Up @@ -84,7 +85,7 @@ def filter_results_from_disable(
return new_results


def main() -> None:
def main() -> int:
parser = argparse.ArgumentParser(
description="Amarna is a static-analyzer for the Cairo programming language.",
epilog=example_usage,
Expand Down Expand Up @@ -170,6 +171,8 @@ def main() -> None:
if args.output or args.print:
output_result(results, args.output, args.print, mode)

return 0


if __name__ == "__main__":
main()
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,15 @@ def get_gathered_data(self) -> List[FunctionEmittingEvent]:
return self.functions_emitting_events

def code_element_function(self, tree: Tree) -> None:
function_name = None

for child in tree.children:
if child.data == "identifier_def":
function_name = str(child.children[0])
break

assert function_name != None

events_emitted_list: List[EventEmitType] = []

for call in tree.find_data("function_call"):
Expand Down
13 changes: 6 additions & 7 deletions amarna/rules/local_rules/UnusedImportRule.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Set
from typing import List, Set
from lark import Tree, Token
from amarna.Result import PositionType, create_result

Expand Down Expand Up @@ -56,21 +56,20 @@ def cairo_file(self, tree: Tree) -> None:
return

# gather all hint code and check if the imports are there
all_hints = ""
all_hints: List[str] = []
for hint in self.original_tree.find_data("code_element_hint"):
all_hints += hint.children[0]
all_hints.append(hint.children[0])

hints_str = "\n".join(all_hints)

# remove imports used in hints
used_in_hints = set()
for unused in unused_imports:
if unused.value in all_hints:
if unused.value in hints_str:
used_in_hints.add(unused)

unused_imports = unused_imports - used_in_hints

# if unused_imports:
# print(f"In file {self.fname}:")

# report unused imports
for arg in sorted(unused_imports):
# print(f"\t{arg.value} imported at line {arg.line}")
Expand Down
3 changes: 1 addition & 2 deletions amarna/rules/post_process_rules/UnenforcedViewRule.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from typing import Dict, List
from amarna.Result import ResultMultiplePositions, result_multiple_positions
from amarna.rules.GenericRule import GenericRule

from amarna.rules.gatherer_rules.DeclaredFunctionsGatherer import (
DeclaredFunctionsGatherer,
Expand All @@ -12,7 +11,7 @@
)


class UnenforcedViewRule(GenericRule):
class UnenforcedViewRule:
"""
Find state modifications in functions with @view decorator.
"""
Expand Down