[PATCH i-g-t 24/33] cocci: Split out _FORTIFY_SOURCE rules

Lyude lyude at redhat.com
Fri Jun 7 23:08:12 UTC 2019


From: Lyude Paul <lyude at redhat.com>

Signed-off-by: Lyude Paul <lyude at redhat.com>
---
 scripts/cocci/igt.cocci                | 41 ------------------------
 scripts/cocci/igt_fortify_source.cocci | 44 ++++++++++++++++++++++++++
 2 files changed, 44 insertions(+), 41 deletions(-)
 create mode 100644 scripts/cocci/igt_fortify_source.cocci

diff --git a/scripts/cocci/igt.cocci b/scripts/cocci/igt.cocci
index 42609da6..86f0c1ed 100644
--- a/scripts/cocci/igt.cocci
+++ b/scripts/cocci/igt.cocci
@@ -6,47 +6,6 @@
 virtual report
 virtual patch
 
-// avoid unused-result warnings when compiling with _FORTIFY_SOURCE defined
- at depends on patch@
-identifier func =~ "^(read|write)$";
-expression list[2] E;
-expression size;
-@@
--func(E, size);
-+igt_assert_eq(func(E, size), size);
-
- at depends on patch@
-expression ptr, size, nmemb, stream;
-@@
--fread(ptr, size, nmemb, stream);
-+igt_assert_eq(fread(ptr, size, nmemb, stream), nmemb);
-
- at depends on patch@
-expression list E;
-@@
--fgets(E);
-+igt_assert(fgets(E));
-
- at depends on patch@
-identifier func =~ "^v?asprintf$";
-expression list E;
-@@
--func(E);
-+igt_assert_neq(func(E), -1);
-
- at unused_res_fortify_source_report depends on report@
-identifier func =~ "^(f?read|write|fgets|v?asprintf)$";
-position p;
-@@
-func at p(...);
-
- at script:python depends on report@
-p << unused_res_fortify_source_report.p;
-func << unused_res_fortify_source_report.func;
-@@
-msg = "WARNING: %s() result unused, will throw warning with _FORTIFY_SOURCE defined" % func
-coccilib.report.print_report(p[0], msg)
-
 // replace open-coded do_ioctl
 @depends on patch@
 expression a, b, c, e;
diff --git a/scripts/cocci/igt_fortify_source.cocci b/scripts/cocci/igt_fortify_source.cocci
new file mode 100644
index 00000000..0cedfc64
--- /dev/null
+++ b/scripts/cocci/igt_fortify_source.cocci
@@ -0,0 +1,44 @@
+// avoid unused-result warnings when compiling with _FORTIFY_SOURCE defined
+
+virtual report
+virtual patch
+
+ at depends on patch@
+identifier func =~ "^(read|write)$";
+expression list[2] E;
+expression size;
+@@
+-func(E, size);
++igt_assert_eq(func(E, size), size);
+
+ at depends on patch@
+expression ptr, size, nmemb, stream;
+@@
+-fread(ptr, size, nmemb, stream);
++igt_assert_eq(fread(ptr, size, nmemb, stream), nmemb);
+
+ at depends on patch@
+expression list E;
+@@
+-fgets(E);
++igt_assert(fgets(E));
+
+ at depends on patch@
+identifier func =~ "^v?asprintf$";
+expression list E;
+@@
+-func(E);
++igt_assert_neq(func(E), -1);
+
+ at unused_res_fortify_source_report depends on report@
+identifier func =~ "^(f?read|write|fgets|v?asprintf)$";
+position p;
+@@
+func at p(...);
+
+ at script:python depends on report@
+p << unused_res_fortify_source_report.p;
+func << unused_res_fortify_source_report.func;
+@@
+msg = "WARNING: %s() result unused, will throw warning with _FORTIFY_SOURCE defined" % func
+coccilib.report.print_report(p[0], msg)
-- 
2.21.0



More information about the Intel-gfx-trybot mailing list