Summary: Those functions have simple enough implementations for infer to understand them Reviewed By: jvillard Differential Revision: D3463084 fbshipit-source-id: f84160fmaster
parent
edc57f70f5
commit
c7d6d904f7
@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright (c) 2016 - 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.
|
||||
*/
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
struct X {
|
||||
X(int f) : f(f) {}
|
||||
int f;
|
||||
};
|
||||
bool operator<(const X& x1, const X& x2) { return x1.f < x2.f; }
|
||||
|
||||
struct X_inv {
|
||||
X_inv(int f) : f(f) {}
|
||||
int f;
|
||||
};
|
||||
bool operator<(const X_inv& x1, const X_inv& x2) { return x1.f > x2.f; }
|
||||
|
||||
int min_int_div0() { return 1 / std::min(1, 0); }
|
||||
|
||||
int min_int_div_1() { return 1 / std::min(-1, 0); }
|
||||
|
||||
int max_int_div1() { return 1 / std::max(1, 0); }
|
||||
|
||||
int max_int_div0() { return 1 / std::max(0, -1); }
|
||||
|
||||
int min_X_div0() {
|
||||
X x0(0), x1(1);
|
||||
return 1 / std::min(x0, x1).f;
|
||||
}
|
||||
|
||||
int max_X_div1() {
|
||||
X x0(0), x1(1);
|
||||
return 1 / std::max(x0, x1).f;
|
||||
}
|
||||
|
||||
int min_X_inv_div1() {
|
||||
X_inv x0(0), x1(1);
|
||||
return 1 / std::min(x0, x1).f;
|
||||
}
|
||||
|
||||
int max_X_inv_div0() {
|
||||
X_inv x0(0), x1(1);
|
||||
return 1 / std::max(x0, x1).f;
|
||||
}
|
@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Copyright (c) 2016 - 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.
|
||||
*/
|
||||
|
||||
package endtoend.cpp;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static utils.matchers.ResultContainsExactly.containsExactly;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import utils.DebuggableTemporaryFolder;
|
||||
import utils.InferException;
|
||||
import utils.InferResults;
|
||||
import utils.InferRunner;
|
||||
|
||||
public class MinMaxNumericTest {
|
||||
|
||||
public static final String FILE =
|
||||
"infer/tests/codetoanalyze/cpp/errors/numeric/min_max.cpp";
|
||||
|
||||
private static ImmutableList<String> inferCmd;
|
||||
|
||||
public static final String DIVIDE_BY_ZERO = "DIVIDE_BY_ZERO";
|
||||
|
||||
@ClassRule
|
||||
public static DebuggableTemporaryFolder folder =
|
||||
new DebuggableTemporaryFolder();
|
||||
|
||||
@BeforeClass
|
||||
public static void runInfer() throws InterruptedException, IOException {
|
||||
inferCmd = InferRunner.createCPPInferCommand(folder, FILE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenInferRunsOnDiv0MethodsErrorIsFound()
|
||||
throws InterruptedException, IOException, InferException {
|
||||
InferResults inferResults = InferRunner.runInferCPP(inferCmd);
|
||||
String[] procedures = {
|
||||
"min_int_div0",
|
||||
"max_int_div0",
|
||||
"min_X_div0",
|
||||
"max_X_inv_div0",
|
||||
};
|
||||
assertThat(
|
||||
"Results should contain the expected divide by zero",
|
||||
inferResults,
|
||||
containsExactly(
|
||||
DIVIDE_BY_ZERO,
|
||||
FILE,
|
||||
procedures
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Reference in new issue