Go to file
David Malcolm 697251b7a1 analyzer: add known stdio functions to sm-file.cc (PR analyzer/58237)
The analyzer ought to report various file leaks for the reproducer in
PR analyzer/58237, such as:

  void f1(const char *str)
  {
    FILE * fp = fopen(str, "r");
    char buf[10];
    while (fgets(buf, 10, fp) != NULL)
    {
      /* Do something with buf */
    }
    /* Missing call to fclose. Need warning here for resource leak */
  }

but fails to do so, due to not recognizing fgets, and thus
conservatively assuming that it could close "fp".

This patch adds a function_set to sm-file.cc of numerous stdio.h
functions that are known to not close the file (and which require a
valid FILE *, but that's a matter for a followup), fixing the issue.

gcc/analyzer/ChangeLog:
	PR analyzer/58237
	* analyzer-selftests.cc (selftest::run_analyzer_selftests): Call
	selftest::analyzer_sm_file_cc_tests.
	* analyzer-selftests.h (selftest::analyzer_sm_file_cc_tests): New
	decl.
	* sm-file.cc: Include "analyzer/function-set.h" and
	"analyzer/analyzer-selftests.h".
	(get_file_using_fns): New function.
	(is_file_using_fn_p): New function.
	(fileptr_state_machine::on_stmt): Return true for known functions.
	(selftest::analyzer_sm_file_cc_tests): New function.

gcc/testsuite/ChangeLog:
	PR analyzer/58237
	* gcc.dg/analyzer/file-1.c (test_4): New.
	* gcc.dg/analyzer/file-pr58237.c: New test.
2020-01-14 20:39:26 -05:00
config
contrib The mentioned auto-generated file is no more part of the 2020-01-14 17:49:37 +01:00
fixincludes
gcc analyzer: add known stdio functions to sm-file.cc (PR analyzer/58237) 2020-01-14 20:39:26 -05:00
gnattools
gotools
include OpenACC 'acc_get_property' cleanup 2020-01-10 23:24:36 +01:00
INSTALL
intl
libada Update copyright years. 2020-01-01 12:51:42 +01:00
libatomic Update copyright years. 2020-01-01 12:51:42 +01:00
libbacktrace Update copyright years. 2020-01-01 12:51:42 +01:00
libcc1 init.c (build_new): Add location_t parameter and use it throughout. 2020-01-07 17:58:18 +00:00
libcpp Add diagnostic paths 2020-01-10 21:22:12 +00:00
libdecnumber Update copyright years. 2020-01-01 12:51:42 +01:00
libffi
libgcc Typo. 2020-01-14 11:14:23 +01:00
libgfortran PR 90374 d0.d, e0.d, es0.d, en0.d, g0.d and ew.d edit descriptors. 2020-01-02 00:57:31 +00:00
libgo gotest: don't use local 2020-01-10 15:28:20 +00:00
libgomp OpenACC 'acc_get_property' cleanup 2020-01-10 23:24:36 +01:00
libhsail-rt Update copyright years. 2020-01-01 12:51:42 +01:00
libiberty Update copyright years. 2020-01-01 12:51:42 +01:00
libitm Update copyright years. 2020-01-01 12:51:42 +01:00
libobjc Fix windows libobjc build (PR libobjc/93099) 2020-01-01 14:16:35 -08:00
liboffloadmic OpenACC 'acc_get_property' cleanup 2020-01-10 23:24:36 +01:00
libphobos Update copyright years. 2020-01-01 12:51:42 +01:00
libquadmath Update copyright years. 2020-01-01 12:51:42 +01:00
libsanitizer
libssp Update copyright years. 2020-01-01 12:51:42 +01:00
libstdc++-v3 libstdc++: Ensure root-dir converted to forward slash (PR93244) 2020-01-13 13:22:48 +00:00
libvtv Update copyright years. 2020-01-01 12:51:42 +01:00
lto-plugin Update copyright years. 2020-01-01 12:51:42 +01:00
maintainer-scripts Replace update_web_docs_libstdcxx_svn with update_web_docs_libstdcxx_git 2020-01-13 21:40:44 +00:00
zlib
.dir-locals.el
.gitattributes
.gitignore
ABOUT-NLS
ar-lib
ChangeLog The mentioned auto-generated file is no more part of the 2020-01-14 17:49:37 +01:00
ChangeLog.jit
ChangeLog.tree-ssa
compile
config-ml.in
config.guess
config.rpath
config.sub
configure
configure.ac
COPYING
COPYING3
COPYING3.LIB
COPYING.LIB
COPYING.RUNTIME
depcomp
install-sh
libtool-ldflags
libtool.m4
lt~obsolete.m4
ltgcc.m4
ltmain.sh
ltoptions.m4
ltsugar.m4
ltversion.m4
MAINTAINERS MAINTAINERS: Update my email address. 2020-01-13 22:10:14 +03:00
Makefile.def
Makefile.in
Makefile.tpl
missing
mkdep
mkinstalldirs
move-if-change
multilib.am
README
symlink-tree
test-driver
ylwrap

This directory contains the GNU Compiler Collection (GCC).

The GNU Compiler Collection is free software.  See the files whose
names start with COPYING for copying permission.  The manuals, and
some of the runtime libraries, are under different terms; see the
individual source files for details.

The directory INSTALL contains copies of the installation information
as HTML and plain text.  The source of this information is
gcc/doc/install.texi.  The installation information includes details
of what is included in the GCC sources and what files GCC installs.

See the file gcc/doc/gcc.texi (together with other files that it
includes) for usage and porting information.  An online readable
version of the manual is in the files gcc/doc/gcc.info*.

See http://gcc.gnu.org/bugs/ for how to report bugs usefully.

Copyright years on GCC source files may be listed using range
notation, e.g., 1987-2012, indicating that every year in the range,
inclusive, is a copyrightable year that could otherwise be listed
individually.