From a416afeb4464379b230dca149fd75dceb84cb085 Mon Sep 17 00:00:00 2001 From: Jules Villard Date: Thu, 12 Nov 2015 05:21:14 -0800 Subject: [PATCH] move error types strings to a new issues.py Summary: public This also cleans up the should_report() function. Reviewed By: jeremydubreil Differential Revision: D2641998 fb-gh-sync-id: b01d445 --- infer/lib/python/inferlib/analyze.py | 47 ++++++---------------------- infer/lib/python/inferlib/issues.py | 40 +++++++++++++++++++++++ 2 files changed, 49 insertions(+), 38 deletions(-) create mode 100644 infer/lib/python/inferlib/issues.py diff --git a/infer/lib/python/inferlib/analyze.py b/infer/lib/python/inferlib/analyze.py index d0ee05f97..dd2b5b3ca 100644 --- a/infer/lib/python/inferlib/analyze.py +++ b/infer/lib/python/inferlib/analyze.py @@ -25,16 +25,13 @@ import tempfile import time import xml.etree.ElementTree as ET -from . import config, jwlib, utils +from . import config, issues, jwlib, utils # Increase the limit of the CSV parser to sys.maxlimit csv.field_size_limit(sys.maxsize) INFER_ANALYZE_BINARY = "InferAnalyze" -ERROR = 'ERROR' -WARNING = 'WARNING' -INFO = 'INFO' def get_infer_version(): try: @@ -262,31 +259,10 @@ def should_report(analyzer, error_kind, error_type, error_bucket): config.ANALYZER_CHECKERS, config.ANALYZER_TRACING, ] - error_kinds = [ERROR, WARNING] - - null_style_bugs = [ - 'NULL_DEREFERENCE', - 'PARAMETER_NOT_NULL_CHECKED', - 'IVAR_NOT_NULL_CHECKED', - 'PREMATURE_NIL_TERMINATION_ARGUMENT', - ] + error_kinds = [issues.ISSUE_KIND_ERROR, issues.ISSUE_KIND_WARNING] null_style_buckets = ['B1', 'B2'] - other_bugs = [ - 'RESOURCE_LEAK', - 'MEMORY_LEAK', - 'RETAIN_CYCLE', - 'ASSERTION_FAILURE', - 'CONTEXT_LEAK', - 'BAD_POINTER_COMPARISON', - 'TAINTED_VALUE_REACHING_SENSITIVE_FUNCTION', - 'STRONG_DELEGATE_WARNING', - # 'CHECKERS_PRINTF_ARGS' - # TODO (#8030397): revert this once all the checkers are moved to Infer - ] - if analyzer in analyzers_whitelist: - # report all issues for eradicate and checkers return True if error_kind not in error_kinds: @@ -295,15 +271,10 @@ def should_report(analyzer, error_kind, error_type, error_bucket): if not error_type: return False - if error_type in null_style_bugs: - if error_bucket and error_bucket in null_style_buckets: - return True - else: - return False - elif error_type in other_bugs: - return True - else: - return False + if error_type in issues.NULL_STYLE_ISSUE_TYPES: + return error_bucket in null_style_buckets + + return error_type in issues.ISSUE_TYPES def should_report_csv(analyzer, row): @@ -390,9 +361,9 @@ def print_errors(json_report, bugs_out): with codecs.open(json_report, 'r', encoding=utils.LOCALE) as file_in: errors = json.load(file_in) - errors = filter( - lambda row: row[utils.JSON_INDEX_KIND] in [ERROR, WARNING], - errors) + errors = filter(lambda row: row[utils.JSON_INDEX_KIND] in + [issues.ISSUE_KIND_ERROR, issues.ISSUE_KIND_WARNING], + errors) with codecs.open(bugs_out, 'w', encoding=utils.LOCALE) as file_out: text_errors_list = [] diff --git a/infer/lib/python/inferlib/issues.py b/infer/lib/python/inferlib/issues.py new file mode 100644 index 000000000..7cbc76176 --- /dev/null +++ b/infer/lib/python/inferlib/issues.py @@ -0,0 +1,40 @@ +# Copyright (c) 2015 - present Facebook, Inc. +# All rights reserved. +# +# This source code is licensed under the BSD style license found in the +# LICENSE file in the root directory of this source tree. An additional grant +# of patent rights can be found in the PATENTS file in the same directory. + +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function +from __future__ import unicode_literals + + +ISSUE_KIND_ERROR = 'ERROR' +ISSUE_KIND_WARNING = 'WARNING' +ISSUE_KIND_INFO = 'INFO' + +ISSUE_TYPES = [ + 'ASSERTION_FAILURE', + 'BAD_POINTER_COMPARISON', + # 'CHECKERS_PRINTF_ARGS' + # TODO (#8030397): revert this once all the checkers are moved to Infer + 'CONTEXT_LEAK', + 'MEMORY_LEAK', + 'RESOURCE_LEAK', + 'RETAIN_CYCLE', + 'STRONG_DELEGATE_WARNING', + 'TAINTED_VALUE_REACHING_SENSITIVE_FUNCTION', + 'IVAR_NOT_NULL_CHECKED', + 'NULL_DEREFERENCE', + 'PARAMETER_NOT_NULL_CHECKED', + 'PREMATURE_NIL_TERMINATION_ARGUMENT', +] + +NULL_STYLE_ISSUE_TYPES = [ + 'IVAR_NOT_NULL_CHECKED', + 'NULL_DEREFERENCE', + 'PARAMETER_NOT_NULL_CHECKED', + 'PREMATURE_NIL_TERMINATION_ARGUMENT', +]