aboutsummaryrefslogtreecommitdiff
path: root/clang/test/Analysis/std-c-library-functions-path-notes.c
diff options
context:
space:
mode:
authorBalázs Kéri <balazs.keri@ericsson.com>2024-02-21 09:18:01 +0100
committerGitHub <noreply@github.com>2024-02-21 09:18:01 +0100
commit1246b64faa5eea1553c1c1aad425c31b701fa6ea (patch)
tree8fdd9ea13a06bdfb21e4805800d3d4f28cc28edd /clang/test/Analysis/std-c-library-functions-path-notes.c
parent7ce1a11f7f436234ce3eaf11c74043937a1ec36b (diff)
downloadllvm-1246b64faa5eea1553c1c1aad425c31b701fa6ea.zip
llvm-1246b64faa5eea1553c1c1aad425c31b701fa6ea.tar.gz
llvm-1246b64faa5eea1553c1c1aad425c31b701fa6ea.tar.bz2
[clang][analyzer] Change modeling of 'fileno' in checkers. (#81842)
Function 'fileno' fails only if invalid pointer is passed, this is a case that is often ignored in source code. The failure case leads to many "false positive" reports when `fileno` returns -1 and this is not checked in the program. Because this, the function is now assumed to not fail (this is assumption that the passed file pointer is correct). The change affects `StdCLibraryFunctionsChecker` and `StreamChecker`.
Diffstat (limited to 'clang/test/Analysis/std-c-library-functions-path-notes.c')
-rw-r--r--clang/test/Analysis/std-c-library-functions-path-notes.c22
1 files changed, 10 insertions, 12 deletions
diff --git a/clang/test/Analysis/std-c-library-functions-path-notes.c b/clang/test/Analysis/std-c-library-functions-path-notes.c
index 4df00fe..6449b71 100644
--- a/clang/test/Analysis/std-c-library-functions-path-notes.c
+++ b/clang/test/Analysis/std-c-library-functions-path-notes.c
@@ -61,24 +61,22 @@ int test_islower(int *x) {
}
int test_bugpath_notes(FILE *f1, char c, FILE *f2) {
- int f = fileno(f2);
- if (f == -1) // \
+ // This test has the purpose of checking that notes appear at correct place.
+ long a = ftell(f2); // no note
+ if (a == -1) // \
// expected-note{{Taking false branch}}
- return 0;
- int l = islower(c);
- f = fileno(f1); // \
- // expected-note{{Value assigned to 'f'}} \
- // expected-note{{Assuming that 'fileno' fails}}
- return dup(f); // \
+ return -1;
+ int l = islower(c); // no note
+ a = ftell(f1); // \
+ // expected-note{{Value assigned to 'a'}} \
+ // expected-note{{Assuming that 'ftell' fails}}
+ return dup(a); // \
// expected-warning{{The 1st argument to 'dup' is -1 but should be >= 0}} \
// expected-note{{The 1st argument to 'dup' is -1 but should be >= 0}}
}
int test_fileno_arg_note(FILE *f1) {
- return dup(fileno(f1)); // \
- // expected-warning{{The 1st argument to 'dup' is < 0 but should be >= 0}} \
- // expected-note{{The 1st argument to 'dup' is < 0 but should be >= 0}} \
- // expected-note{{Assuming that 'fileno' fails}}
+ return dup(fileno(f1)); // no warning
}
int test_readlink_bufsize_zero(char *Buf, size_t Bufsize) {