[committed] analyzer: add regression test for leak false positive
David Malcolm
dmalcolm@redhat.com
Mon Sep 14 16:35:50 GMT 2020
Downstream bug report:
https://bugzilla.redhat.com/show_bug.cgi?id=1878600
describes a false positive from -Wanalyzer-file-leak seen with
gcc 10.2, but which has been fixed in gcc 11.
This patch adds the reproducer as a regression test.
Successfully tested on x86_64-pc-linux-gnu.
Pushed to master as 00adddd65689d995d8bdf306d0850c852ff0fd25.
gcc/testsuite/ChangeLog:
* gcc.dg/analyzer/rhbz1878600.c: New test.
---
gcc/testsuite/gcc.dg/analyzer/rhbz1878600.c | 34 +++++++++++++++++++++
1 file changed, 34 insertions(+)
create mode 100644 gcc/testsuite/gcc.dg/analyzer/rhbz1878600.c
diff --git a/gcc/testsuite/gcc.dg/analyzer/rhbz1878600.c b/gcc/testsuite/gcc.dg/analyzer/rhbz1878600.c
new file mode 100644
index 00000000000..9f6ccb6dc27
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/analyzer/rhbz1878600.c
@@ -0,0 +1,34 @@
+#include <stdio.h>
+
+#define INI_MAX_LINE 200
+
+typedef char* (*ini_reader)(char* str, int num, void* stream);
+
+int ini_parse(const char* filename);
+
+static int ini_parse_stream(ini_reader reader, void* stream)
+{
+ char line[INI_MAX_LINE];
+ int max_line = INI_MAX_LINE;
+ while (reader(line, max_line, stream) != NULL)
+ ;
+ return 0;
+}
+
+static int ini_parse_file(FILE* file)
+{
+ return ini_parse_stream((ini_reader)fgets, file);
+}
+
+int ini_parse(const char* filename)
+{
+ FILE* file;
+ int error;
+
+ file = fopen(filename, "r");
+ if (!file)
+ return -1;
+ error = ini_parse_file(file);
+ fclose(file);
+ return error;
+}
--
2.26.2
More information about the Gcc-patches
mailing list