2017-03-04 02:02:02 +08:00
|
|
|
// RUN: %clang_analyze_cc1 -analyzer-checker=alpha.unix.Stream -analyzer-store region -verify %s
|
2010-06-16 13:38:05 +08:00
|
|
|
|
|
|
|
typedef __typeof__(sizeof(int)) size_t;
|
[clang][analyzer] Using CallDescription in StreamChecker.
Summary:
Recognization of function names is done now with the CallDescription
class instead of using IdentifierInfo. This means function name and
argument count is compared too.
A new check for filtering not global-C-functions was added.
Test was updated.
Reviewers: Szelethus, NoQ, baloghadamsoftware, Charusso
Reviewed By: Szelethus, NoQ, Charusso
Subscribers: rnkovacs, xazax.hun, baloghadamsoftware, szepet, a.sidorin, mikhail.ramalho, donat.nagy, Charusso, dkrupp, Szelethus, gamesh411, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D67706
2019-10-31 19:09:44 +08:00
|
|
|
typedef __typeof__(sizeof(int)) fpos_t;
|
2010-06-16 13:38:05 +08:00
|
|
|
typedef struct _IO_FILE FILE;
|
2010-06-18 10:47:46 +08:00
|
|
|
#define SEEK_SET 0 /* Seek from beginning of file. */
|
|
|
|
#define SEEK_CUR 1 /* Seek from current position. */
|
|
|
|
#define SEEK_END 2 /* Seek from end of file. */
|
|
|
|
extern FILE *fopen(const char *path, const char *mode);
|
2010-07-22 22:01:01 +08:00
|
|
|
extern FILE *tmpfile(void);
|
2010-07-19 09:52:29 +08:00
|
|
|
extern int fclose(FILE *fp);
|
2010-06-18 10:47:46 +08:00
|
|
|
extern size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream);
|
[clang][analyzer] Using CallDescription in StreamChecker.
Summary:
Recognization of function names is done now with the CallDescription
class instead of using IdentifierInfo. This means function name and
argument count is compared too.
A new check for filtering not global-C-functions was added.
Test was updated.
Reviewers: Szelethus, NoQ, baloghadamsoftware, Charusso
Reviewed By: Szelethus, NoQ, Charusso
Subscribers: rnkovacs, xazax.hun, baloghadamsoftware, szepet, a.sidorin, mikhail.ramalho, donat.nagy, Charusso, dkrupp, Szelethus, gamesh411, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D67706
2019-10-31 19:09:44 +08:00
|
|
|
extern size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream);
|
2010-06-18 10:47:46 +08:00
|
|
|
extern int fseek (FILE *__stream, long int __off, int __whence);
|
|
|
|
extern long int ftell (FILE *__stream);
|
|
|
|
extern void rewind (FILE *__stream);
|
[clang][analyzer] Using CallDescription in StreamChecker.
Summary:
Recognization of function names is done now with the CallDescription
class instead of using IdentifierInfo. This means function name and
argument count is compared too.
A new check for filtering not global-C-functions was added.
Test was updated.
Reviewers: Szelethus, NoQ, baloghadamsoftware, Charusso
Reviewed By: Szelethus, NoQ, Charusso
Subscribers: rnkovacs, xazax.hun, baloghadamsoftware, szepet, a.sidorin, mikhail.ramalho, donat.nagy, Charusso, dkrupp, Szelethus, gamesh411, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D67706
2019-10-31 19:09:44 +08:00
|
|
|
extern int fgetpos(FILE *stream, fpos_t *pos);
|
|
|
|
extern int fsetpos(FILE *stream, const fpos_t *pos);
|
|
|
|
extern void clearerr(FILE *stream);
|
|
|
|
extern int feof(FILE *stream);
|
|
|
|
extern int ferror(FILE *stream);
|
|
|
|
extern int fileno(FILE *stream);
|
2010-06-16 13:38:05 +08:00
|
|
|
|
[clang][analyzer] Using CallDescription in StreamChecker.
Summary:
Recognization of function names is done now with the CallDescription
class instead of using IdentifierInfo. This means function name and
argument count is compared too.
A new check for filtering not global-C-functions was added.
Test was updated.
Reviewers: Szelethus, NoQ, baloghadamsoftware, Charusso
Reviewed By: Szelethus, NoQ, Charusso
Subscribers: rnkovacs, xazax.hun, baloghadamsoftware, szepet, a.sidorin, mikhail.ramalho, donat.nagy, Charusso, dkrupp, Szelethus, gamesh411, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D67706
2019-10-31 19:09:44 +08:00
|
|
|
void check_fread() {
|
|
|
|
FILE *fp = tmpfile();
|
|
|
|
fread(0, 0, 0, fp); // expected-warning {{Stream pointer might be NULL}}
|
|
|
|
fclose(fp);
|
2010-06-16 13:38:05 +08:00
|
|
|
}
|
2010-06-18 10:47:46 +08:00
|
|
|
|
[clang][analyzer] Using CallDescription in StreamChecker.
Summary:
Recognization of function names is done now with the CallDescription
class instead of using IdentifierInfo. This means function name and
argument count is compared too.
A new check for filtering not global-C-functions was added.
Test was updated.
Reviewers: Szelethus, NoQ, baloghadamsoftware, Charusso
Reviewed By: Szelethus, NoQ, Charusso
Subscribers: rnkovacs, xazax.hun, baloghadamsoftware, szepet, a.sidorin, mikhail.ramalho, donat.nagy, Charusso, dkrupp, Szelethus, gamesh411, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D67706
2019-10-31 19:09:44 +08:00
|
|
|
void check_fwrite() {
|
|
|
|
FILE *fp = tmpfile();
|
|
|
|
fwrite(0, 0, 0, fp); // expected-warning {{Stream pointer might be NULL}}
|
|
|
|
fclose(fp);
|
2010-06-18 10:47:46 +08:00
|
|
|
}
|
|
|
|
|
[clang][analyzer] Using CallDescription in StreamChecker.
Summary:
Recognization of function names is done now with the CallDescription
class instead of using IdentifierInfo. This means function name and
argument count is compared too.
A new check for filtering not global-C-functions was added.
Test was updated.
Reviewers: Szelethus, NoQ, baloghadamsoftware, Charusso
Reviewed By: Szelethus, NoQ, Charusso
Subscribers: rnkovacs, xazax.hun, baloghadamsoftware, szepet, a.sidorin, mikhail.ramalho, donat.nagy, Charusso, dkrupp, Szelethus, gamesh411, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D67706
2019-10-31 19:09:44 +08:00
|
|
|
void check_fseek() {
|
|
|
|
FILE *fp = tmpfile();
|
|
|
|
fseek(fp, 0, 0); // expected-warning {{Stream pointer might be NULL}}
|
|
|
|
fclose(fp);
|
|
|
|
}
|
|
|
|
|
|
|
|
void check_ftell() {
|
|
|
|
FILE *fp = tmpfile();
|
|
|
|
ftell(fp); // expected-warning {{Stream pointer might be NULL}}
|
|
|
|
fclose(fp);
|
|
|
|
}
|
|
|
|
|
|
|
|
void check_rewind() {
|
|
|
|
FILE *fp = tmpfile();
|
|
|
|
rewind(fp); // expected-warning {{Stream pointer might be NULL}}
|
|
|
|
fclose(fp);
|
|
|
|
}
|
|
|
|
|
|
|
|
void check_fgetpos() {
|
|
|
|
FILE *fp = tmpfile();
|
|
|
|
fpos_t pos;
|
|
|
|
fgetpos(fp, &pos); // expected-warning {{Stream pointer might be NULL}}
|
|
|
|
fclose(fp);
|
|
|
|
}
|
|
|
|
|
|
|
|
void check_fsetpos() {
|
|
|
|
FILE *fp = tmpfile();
|
|
|
|
fpos_t pos;
|
|
|
|
fsetpos(fp, &pos); // expected-warning {{Stream pointer might be NULL}}
|
|
|
|
fclose(fp);
|
|
|
|
}
|
|
|
|
|
|
|
|
void check_clearerr() {
|
|
|
|
FILE *fp = tmpfile();
|
|
|
|
clearerr(fp); // expected-warning {{Stream pointer might be NULL}}
|
|
|
|
fclose(fp);
|
|
|
|
}
|
|
|
|
|
|
|
|
void check_feof() {
|
|
|
|
FILE *fp = tmpfile();
|
|
|
|
feof(fp); // expected-warning {{Stream pointer might be NULL}}
|
|
|
|
fclose(fp);
|
|
|
|
}
|
|
|
|
|
|
|
|
void check_ferror() {
|
|
|
|
FILE *fp = tmpfile();
|
|
|
|
ferror(fp); // expected-warning {{Stream pointer might be NULL}}
|
|
|
|
fclose(fp);
|
2010-06-18 10:47:46 +08:00
|
|
|
}
|
|
|
|
|
[clang][analyzer] Using CallDescription in StreamChecker.
Summary:
Recognization of function names is done now with the CallDescription
class instead of using IdentifierInfo. This means function name and
argument count is compared too.
A new check for filtering not global-C-functions was added.
Test was updated.
Reviewers: Szelethus, NoQ, baloghadamsoftware, Charusso
Reviewed By: Szelethus, NoQ, Charusso
Subscribers: rnkovacs, xazax.hun, baloghadamsoftware, szepet, a.sidorin, mikhail.ramalho, donat.nagy, Charusso, dkrupp, Szelethus, gamesh411, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D67706
2019-10-31 19:09:44 +08:00
|
|
|
void check_fileno() {
|
|
|
|
FILE *fp = tmpfile();
|
|
|
|
fileno(fp); // expected-warning {{Stream pointer might be NULL}}
|
|
|
|
fclose(fp);
|
|
|
|
}
|
|
|
|
|
|
|
|
void f_open(void) {
|
2010-06-18 10:47:46 +08:00
|
|
|
FILE *p = fopen("foo", "r");
|
[clang][analyzer] Using CallDescription in StreamChecker.
Summary:
Recognization of function names is done now with the CallDescription
class instead of using IdentifierInfo. This means function name and
argument count is compared too.
A new check for filtering not global-C-functions was added.
Test was updated.
Reviewers: Szelethus, NoQ, baloghadamsoftware, Charusso
Reviewed By: Szelethus, NoQ, Charusso
Subscribers: rnkovacs, xazax.hun, baloghadamsoftware, szepet, a.sidorin, mikhail.ramalho, donat.nagy, Charusso, dkrupp, Szelethus, gamesh411, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D67706
2019-10-31 19:09:44 +08:00
|
|
|
char buf[1024];
|
|
|
|
fread(buf, 1, 1, p); // expected-warning {{Stream pointer might be NULL}}
|
2010-07-23 22:14:59 +08:00
|
|
|
fclose(p);
|
2010-06-18 10:47:46 +08:00
|
|
|
}
|
|
|
|
|
[clang][analyzer] Using CallDescription in StreamChecker.
Summary:
Recognization of function names is done now with the CallDescription
class instead of using IdentifierInfo. This means function name and
argument count is compared too.
A new check for filtering not global-C-functions was added.
Test was updated.
Reviewers: Szelethus, NoQ, baloghadamsoftware, Charusso
Reviewed By: Szelethus, NoQ, Charusso
Subscribers: rnkovacs, xazax.hun, baloghadamsoftware, szepet, a.sidorin, mikhail.ramalho, donat.nagy, Charusso, dkrupp, Szelethus, gamesh411, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D67706
2019-10-31 19:09:44 +08:00
|
|
|
void f_seek(void) {
|
2010-06-24 21:36:41 +08:00
|
|
|
FILE *p = fopen("foo", "r");
|
|
|
|
if (!p)
|
|
|
|
return;
|
|
|
|
fseek(p, 1, SEEK_SET); // no-warning
|
Allow multiple PathDiagnosticConsumers to be used with a BugReporter at the same time.
This fixes several issues:
- removes egregious hack where PlistDiagnosticConsumer would forward to HTMLDiagnosticConsumer,
but diagnostics wouldn't be generated consistently in the same way if PlistDiagnosticConsumer
was used by itself.
- emitting diagnostics to the terminal (using clang's diagnostic machinery) is no longer a special
case, just another PathDiagnosticConsumer. This also magically resolved some duplicate warnings,
as we now use PathDiagnosticConsumer's diagnostic pruning, which has scope for the entire translation
unit, not just the scope of a BugReporter (which is limited to a particular ExprEngine).
As an interesting side-effect, diagnostics emitted to the terminal also have their trailing "." stripped,
just like with diagnostics emitted to plists and HTML. This required some tests to be updated, but now
the tests have higher fidelity with what users will see.
There are some inefficiencies in this patch. We currently generate the report graph (from the ExplodedGraph)
once per PathDiagnosticConsumer, which is a bit wasteful, but that could be pulled up higher in the
logic stack. There is some intended duplication, however, as we now generate different PathDiagnostics (for the same issue)
for different PathDiagnosticConsumers. This is necessary to produce the diagnostics that a particular
consumer expects.
llvm-svn: 162028
2012-08-17 01:45:23 +08:00
|
|
|
fseek(p, 1, 3); // expected-warning {{The whence argument to fseek() should be SEEK_SET, SEEK_END, or SEEK_CUR}}
|
2010-07-23 22:14:59 +08:00
|
|
|
fclose(p);
|
2010-06-24 21:36:41 +08:00
|
|
|
}
|
2010-07-19 09:52:29 +08:00
|
|
|
|
[clang][analyzer] Using CallDescription in StreamChecker.
Summary:
Recognization of function names is done now with the CallDescription
class instead of using IdentifierInfo. This means function name and
argument count is compared too.
A new check for filtering not global-C-functions was added.
Test was updated.
Reviewers: Szelethus, NoQ, baloghadamsoftware, Charusso
Reviewed By: Szelethus, NoQ, Charusso
Subscribers: rnkovacs, xazax.hun, baloghadamsoftware, szepet, a.sidorin, mikhail.ramalho, donat.nagy, Charusso, dkrupp, Szelethus, gamesh411, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D67706
2019-10-31 19:09:44 +08:00
|
|
|
void f_double_close(void) {
|
2010-07-19 09:52:29 +08:00
|
|
|
FILE *p = fopen("foo", "r");
|
|
|
|
fclose(p);
|
Allow multiple PathDiagnosticConsumers to be used with a BugReporter at the same time.
This fixes several issues:
- removes egregious hack where PlistDiagnosticConsumer would forward to HTMLDiagnosticConsumer,
but diagnostics wouldn't be generated consistently in the same way if PlistDiagnosticConsumer
was used by itself.
- emitting diagnostics to the terminal (using clang's diagnostic machinery) is no longer a special
case, just another PathDiagnosticConsumer. This also magically resolved some duplicate warnings,
as we now use PathDiagnosticConsumer's diagnostic pruning, which has scope for the entire translation
unit, not just the scope of a BugReporter (which is limited to a particular ExprEngine).
As an interesting side-effect, diagnostics emitted to the terminal also have their trailing "." stripped,
just like with diagnostics emitted to plists and HTML. This required some tests to be updated, but now
the tests have higher fidelity with what users will see.
There are some inefficiencies in this patch. We currently generate the report graph (from the ExplodedGraph)
once per PathDiagnosticConsumer, which is a bit wasteful, but that could be pulled up higher in the
logic stack. There is some intended duplication, however, as we now generate different PathDiagnostics (for the same issue)
for different PathDiagnosticConsumers. This is necessary to produce the diagnostics that a particular
consumer expects.
llvm-svn: 162028
2012-08-17 01:45:23 +08:00
|
|
|
fclose(p); // expected-warning {{Try to close a file Descriptor already closed. Cause undefined behaviour}}
|
2010-07-19 09:52:29 +08:00
|
|
|
}
|
2010-07-22 22:01:01 +08:00
|
|
|
|
[clang][analyzer] Using CallDescription in StreamChecker.
Summary:
Recognization of function names is done now with the CallDescription
class instead of using IdentifierInfo. This means function name and
argument count is compared too.
A new check for filtering not global-C-functions was added.
Test was updated.
Reviewers: Szelethus, NoQ, baloghadamsoftware, Charusso
Reviewed By: Szelethus, NoQ, Charusso
Subscribers: rnkovacs, xazax.hun, baloghadamsoftware, szepet, a.sidorin, mikhail.ramalho, donat.nagy, Charusso, dkrupp, Szelethus, gamesh411, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D67706
2019-10-31 19:09:44 +08:00
|
|
|
void f_leak(int c) {
|
2010-07-23 22:14:59 +08:00
|
|
|
FILE *p = fopen("foo.c", "r");
|
|
|
|
if(c)
|
Allow multiple PathDiagnosticConsumers to be used with a BugReporter at the same time.
This fixes several issues:
- removes egregious hack where PlistDiagnosticConsumer would forward to HTMLDiagnosticConsumer,
but diagnostics wouldn't be generated consistently in the same way if PlistDiagnosticConsumer
was used by itself.
- emitting diagnostics to the terminal (using clang's diagnostic machinery) is no longer a special
case, just another PathDiagnosticConsumer. This also magically resolved some duplicate warnings,
as we now use PathDiagnosticConsumer's diagnostic pruning, which has scope for the entire translation
unit, not just the scope of a BugReporter (which is limited to a particular ExprEngine).
As an interesting side-effect, diagnostics emitted to the terminal also have their trailing "." stripped,
just like with diagnostics emitted to plists and HTML. This required some tests to be updated, but now
the tests have higher fidelity with what users will see.
There are some inefficiencies in this patch. We currently generate the report graph (from the ExplodedGraph)
once per PathDiagnosticConsumer, which is a bit wasteful, but that could be pulled up higher in the
logic stack. There is some intended duplication, however, as we now generate different PathDiagnostics (for the same issue)
for different PathDiagnosticConsumers. This is necessary to produce the diagnostics that a particular
consumer expects.
llvm-svn: 162028
2012-08-17 01:45:23 +08:00
|
|
|
return; // expected-warning {{Opened File never closed. Potential Resource leak}}
|
2010-07-23 22:14:59 +08:00
|
|
|
fclose(p);
|
|
|
|
}
|
|
|
|
|
[clang][analyzer] Using CallDescription in StreamChecker.
Summary:
Recognization of function names is done now with the CallDescription
class instead of using IdentifierInfo. This means function name and
argument count is compared too.
A new check for filtering not global-C-functions was added.
Test was updated.
Reviewers: Szelethus, NoQ, baloghadamsoftware, Charusso
Reviewed By: Szelethus, NoQ, Charusso
Subscribers: rnkovacs, xazax.hun, baloghadamsoftware, szepet, a.sidorin, mikhail.ramalho, donat.nagy, Charusso, dkrupp, Szelethus, gamesh411, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D67706
2019-10-31 19:09:44 +08:00
|
|
|
FILE *f_null_checked(void) {
|
2010-07-23 22:14:59 +08:00
|
|
|
FILE *p = fopen("foo.c", "r");
|
|
|
|
if (p)
|
|
|
|
return p; // no-warning
|
|
|
|
else
|
|
|
|
return 0;
|
2010-07-22 22:01:01 +08:00
|
|
|
}
|
2010-08-06 08:04:40 +08:00
|
|
|
|
|
|
|
void pr7831(FILE *fp) {
|
|
|
|
fclose(fp); // no-warning
|
|
|
|
}
|
2010-09-08 04:45:26 +08:00
|
|
|
|
|
|
|
// PR 8081 - null pointer crash when 'whence' is not an integer constant
|
|
|
|
void pr8081(FILE *stream, long offset, int whence) {
|
|
|
|
fseek(stream, offset, whence);
|
|
|
|
}
|