Skip to content

Commit

Permalink
[topl] A new test illustrating a false positive
Browse files Browse the repository at this point in the history
Summary: This comes from github issue #1757

Reviewed By: Gabisampaio

Differential Revision: D45279395

fbshipit-source-id: 805da10fe160871999be58b67d91c8ee11fa97c6
  • Loading branch information
rgrig authored and facebook-github-bot committed Apr 28, 2023
1 parent bf340c2 commit 78cad01
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 0 deletions.
13 changes: 13 additions & 0 deletions infer/tests/codetoanalyze/java/topl/validRange/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.

TESTS_DIR = ../../../..

INFER_OPTIONS = --topl-properties validRange.topl --topl-only
INFERPRINT_OPTIONS = --issues-tests

SOURCES = $(wildcard *.java)

include $(TESTS_DIR)/javac.make
23 changes: 23 additions & 0 deletions infer/tests/codetoanalyze/java/topl/validRange/Valid.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
class Valid {
public static boolean is_valid_vn(int i) {
return i >= 1 && i <= 10;
}

public static void id_to_vn(int i) {}

public static void safe_call(int id) {
if (is_valid_vn(id)) {
id_to_vn(id);
}
}

public static void FP_testOk() {
safe_call(1);
}
}
1 change: 1 addition & 0 deletions infer/tests/codetoanalyze/java/topl/validRange/issues.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
codetoanalyze/java/topl/validRange/Valid.java, Valid.FP_testOk():void, 0, TOPL_ERROR, no_bucket, ERROR, [call to void Valid.safe_call(int),call to boolean Valid.is_valid_vn(int),call to void Valid.id_to_vn(int)]
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
property ValidVN
prefix "Valid"
start -> error: "id_to_vn"(IgnoreArg, IgnoreRet)
start -> ok: "is_valid_vn"(Arg, Ret) when Ret != 0 => good := Arg
ok -> ok: "is_valid_vn"(Arg, Ret) when Ret != 0 => good := Arg
ok -> error: "id_to_vn"(Arg, IgnoreRet) when Arg != good

0 comments on commit 78cad01

Please sign in to comment.