[gcc(refs/vendors/ARM/heads/arm-perf-staging)] PR c/93640 - The write_only and read_write attributes can be mistyped due to invalid strncmp size ar
Tamar Christina
tnfchris@gcc.gnu.org
Fri Jul 17 12:58:26 GMT 2020
https://gcc.gnu.org/g:0cc575e4d8b68b743e07da02a74733f9b5cb585a
commit 0cc575e4d8b68b743e07da02a74733f9b5cb585a
Author: Martin Sebor <msebor@redhat.com>
Date: Mon Feb 10 10:27:00 2020 -0700
PR c/93640 - The write_only and read_write attributes can be mistyped due to invalid strncmp size argument
gcc/c-family/ChangeLog:
PR c/93640
* c-attribs.c (handle_access_attribute): Correct off-by-one mistakes.
gcc/testsuite/ChangeLog:
PR c/93640
* gcc.dg/attr-access.c: New test.
Diff:
---
gcc/c-family/ChangeLog | 5 +++++
gcc/c-family/c-attribs.c | 4 ++--
gcc/testsuite/ChangeLog | 5 +++++
gcc/testsuite/gcc.dg/attr-access.c | 21 +++++++++++++++++++++
4 files changed, 33 insertions(+), 2 deletions(-)
diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog
index 4ba4448006a..cabf850a921 100644
--- a/gcc/c-family/ChangeLog
+++ b/gcc/c-family/ChangeLog
@@ -1,3 +1,8 @@
+2020-02-10 Martin Sebor <msebor@redhat.com>
+
+ PR c/93640
+ * c-attribs.c (handle_access_attribute): Correct off-by-one mistakes.
+
2020-02-10 Jakub Jelinek <jakub@redhat.com>
PR other/93641
diff --git a/gcc/c-family/c-attribs.c b/gcc/c-family/c-attribs.c
index 7ec6fc848ac..2ea5fd5ff46 100644
--- a/gcc/c-family/c-attribs.c
+++ b/gcc/c-family/c-attribs.c
@@ -3999,8 +3999,8 @@ handle_access_attribute (tree *node, tree name, tree args,
}
const bool read_only = strncmp (ps, "read_only", 9) == 0;
- const bool write_only = strncmp (ps, "write_only", 9) == 0;
- if (!read_only && !write_only && strncmp (ps, "read_write", 9))
+ const bool write_only = strncmp (ps, "write_only", 10) == 0;
+ if (!read_only && !write_only && strncmp (ps, "read_write", 10))
{
error ("attribute %qE invalid mode %qs; expected one of "
"%qs, %qs, or %qs", name, access_str,
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index f81fd129db9..c6b1c72575f 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2020-02-10 Martin Sebor <msebor@redhat.com>
+
+ PR c/93640
+ * gcc.dg/attr-access.c: New test.
+
2020-02-10 Hans-Peter Nilsson <hp@axis.com>
* gcc.target/cris/cris.exp (check_effective_target_cc0): New.
diff --git a/gcc/testsuite/gcc.dg/attr-access.c b/gcc/testsuite/gcc.dg/attr-access.c
new file mode 100644
index 00000000000..f859c461b96
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/attr-access.c
@@ -0,0 +1,21 @@
+/* PR c/93640 - The write_only and read_write attributes can be mistyped
+ due to invalid strncmp size argument
+ { dg-do compile }
+ { dg-options "-Wall" } */
+
+__attribute__ ((access (read_onl))) int f0 (char*); // { dg-error "attribute 'access' invalid mode 'read_onl'" }
+__attribute__ ((access (write_onl))) int f1 (char*); // { dg-error "attribute 'access' invalid mode 'write_onl'" }
+__attribute__ ((access (read_writ))) int f2 (char*); // { dg-error "attribute 'access' invalid mode 'read_writ'" }
+
+__attribute__ ((access (read_onlX))) int f3 (char*); // { dg-error "attribute 'access' invalid mode 'read_onlX'" }
+__attribute__ ((access (write_onlX))) int f4 (char*); // { dg-error "attribute 'access' invalid mode 'write_onlX'" }
+__attribute__ ((access (read_writX))) int f5 (char*); // { dg-error "attribute 'access' invalid mode 'read_writX'" }
+
+
+__attribute__ ((access (read_onl, 1))) int f7 (char*); // { dg-error "attribute 'access' invalid mode 'read_onl'" }
+__attribute__ ((access (write_onl, 1))) int f8 (char*); // { dg-error "attribute 'access' invalid mode 'write_onl'" }
+__attribute__ ((access (read_writ, 1))) int f9 (char*); // { dg-error "attribute 'access' invalid mode 'read_writ'" }
+
+__attribute__ ((access (read_onlX, 1))) int f10 (char*); // { dg-error "attribute 'access' invalid mode 'read_onlX'" }
+__attribute__ ((access (write_onlX, 1))) int f11 (char*); // { dg-error "attribute 'access' invalid mode 'write_onlX'" }
+__attribute__ ((access (read_writX, 1))) int f12 (char*); // { dg-error "attribute 'access' invalid mode 'read_writX'" }
More information about the Gcc-cvs
mailing list