Summary: @public Sorting the fields in structs and classes. Was needed in the backend and forgotten. Fixes the github issue https://github.com/facebook/infer/issues/90. Test Plan: Added a new test that shows that we now get a spec for the example from the github issue.master
parent
843e600bb1
commit
510fc4ed25
@ -0,0 +1,12 @@
|
||||
|
||||
SOURCES = $(shell ls *.c)
|
||||
OBJECTS = $(SOURCES:.c=.o)
|
||||
|
||||
all: clean $(OBJECTS)
|
||||
echo $(OBJECTS)
|
||||
|
||||
.c.o:
|
||||
${CC} -c $<
|
||||
|
||||
clean:
|
||||
rm -rf $(OBJECTS)
|
@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Copyright (c) 2015 - Facebook.
|
||||
* All rights reserved.
|
||||
*/
|
||||
struct l2 {
|
||||
int b;
|
||||
struct l2 *a;
|
||||
};
|
||||
|
||||
int add2(struct l2 *l) {
|
||||
int r = 0;
|
||||
for (; l; l = l->a) {
|
||||
r += l->b;
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
/* Divide by zero error shows that we get a spec for add2 */
|
||||
int main() {
|
||||
int res = add2(0);
|
||||
return 5/res;
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright (c) 2013- Facebook.
|
||||
* All rights reserved.
|
||||
*/
|
||||
|
||||
package endtoend.c;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static utils.matchers.ResultContainsExactly.containsExactly;
|
||||
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import utils.InferException;
|
||||
import utils.InferResults;
|
||||
|
||||
public class ListsTest {
|
||||
|
||||
public static final String SOURCE_FILE = "lists/lists.c";
|
||||
|
||||
public static final String DIVIDE_BY_ZERO = "DIVIDE_BY_ZERO";
|
||||
|
||||
private static InferResults inferResults;
|
||||
|
||||
@BeforeClass
|
||||
public static void runInfer() throws InterruptedException, IOException {
|
||||
inferResults = InferResults.loadCInferResults(DivideByZeroTest.class, SOURCE_FILE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenInferRunsOnDivideByZeroThenDivideByZeroIsFound()
|
||||
throws InterruptedException, IOException, InferException {
|
||||
String[] procedures = {"main"};
|
||||
assertThat(
|
||||
"Results should contain divide by zero error",
|
||||
inferResults,
|
||||
containsExactly(
|
||||
DIVIDE_BY_ZERO,
|
||||
SOURCE_FILE,
|
||||
procedures
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
Reference in new issue