aboutsummaryrefslogtreecommitdiff
path: root/gcc/c-family
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2019-11-23 11:06:26 +0100
committerJakub Jelinek <jakub@gcc.gnu.org>2019-11-23 11:06:26 +0100
commit1fbf51cb84cb1000fac324ef11554c36084cd537 (patch)
tree13ae1acd889f6bf845b15c15d9f2176419ea4121 /gcc/c-family
parentba585b91532b5cb382f1e2d21be50e728bca1da0 (diff)
downloadgcc-1fbf51cb84cb1000fac324ef11554c36084cd537.zip
gcc-1fbf51cb84cb1000fac324ef11554c36084cd537.tar.gz
gcc-1fbf51cb84cb1000fac324ef11554c36084cd537.tar.bz2
re PR middle-end/83859 (Please add new attribute which will establish relation between parameters for buffer and its size)
PR middle-end/83859 * doc/extend.texi (attribute access): Fix a typo. * c-attribs.c (append_access_attrs): Avoid buffer overflow. Avoid memory leak. Use XNEWVEC macro. Use auto_diagnostic_group to group warning with inform together. (handle_access_attribute): Formatting fix. From-SVN: r278641
Diffstat (limited to 'gcc/c-family')
-rw-r--r--gcc/c-family/ChangeLog8
-rw-r--r--gcc/c-family/c-attribs.c16
2 files changed, 20 insertions, 4 deletions
diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog
index 1cf0fef..281d7f4 100644
--- a/gcc/c-family/ChangeLog
+++ b/gcc/c-family/ChangeLog
@@ -1,3 +1,11 @@
+2019-11-23 Jakub Jelinek <jakub@redhat.com>
+
+ PR middle-end/83859
+ * c-attribs.c (append_access_attrs): Avoid buffer overflow. Avoid
+ memory leak. Use XNEWVEC macro. Use auto_diagnostic_group to
+ group warning with inform together.
+ (handle_access_attribute): Formatting fix.
+
2019-11-22 Jakub Jelinek <jakub@redhat.com>
PR c/90677
diff --git a/gcc/c-family/c-attribs.c b/gcc/c-family/c-attribs.c
index e307160..cc006f3 100644
--- a/gcc/c-family/c-attribs.c
+++ b/gcc/c-family/c-attribs.c
@@ -3840,7 +3840,7 @@ append_access_attrs (tree t, tree attrs, const char *attrstr,
if (idxs[1])
n2 = sprintf (attrspec + n1 + 1, "%u", (unsigned) idxs[1] - 1);
- size_t newlen = n1 + n2;
+ size_t newlen = n1 + n2 + !!n2;
char *newspec = attrspec;
if (tree acs = lookup_attribute ("access", attrs))
@@ -3869,6 +3869,7 @@ append_access_attrs (tree t, tree attrs, const char *attrstr,
if (*attrspec != pos[-1])
{
/* Mismatch in access mode. */
+ auto_diagnostic_group d;
if (warning (OPT_Wattributes,
"attribute %qs mismatch with mode %qs",
attrstr,
@@ -3884,6 +3885,7 @@ append_access_attrs (tree t, tree attrs, const char *attrstr,
if ((n2 && pos[n1 - 1] != ','))
{
/* Mismatch in the presence of the size argument. */
+ auto_diagnostic_group d;
if (warning (OPT_Wattributes,
"attribute %qs positional argument 2 conflicts "
"with previous designation",
@@ -3897,6 +3899,7 @@ append_access_attrs (tree t, tree attrs, const char *attrstr,
if (!n2 && pos[n1 - 1] == ',')
{
/* Mismatch in the presence of the size argument. */
+ auto_diagnostic_group d;
if (warning (OPT_Wattributes,
"attribute %qs missing positional argument 2 "
"provided in previous designation",
@@ -3910,6 +3913,7 @@ append_access_attrs (tree t, tree attrs, const char *attrstr,
if (n2 && strncmp (attrstr + n1 + 1, pos + n1, n2))
{
/* Mismatch in the value of the size argument. */
+ auto_diagnostic_group d;
if (warning (OPT_Wattributes,
"attribute %qs mismatch positional argument "
"values %i and %i",
@@ -3929,7 +3933,7 @@ append_access_attrs (tree t, tree attrs, const char *attrstr,
attrspec[n1] = ',';
size_t len = strlen (str);
- newspec = (char *) xmalloc (newlen + len + 1);
+ newspec = XNEWVEC (char, newlen + len + 1);
strcpy (newspec, str);
strcpy (newspec + len, attrspec);
newlen += len;
@@ -3938,7 +3942,10 @@ append_access_attrs (tree t, tree attrs, const char *attrstr,
/* Connect the two substrings formatted above into a single one. */
attrspec[n1] = ',';
- return build_string (newlen + 1, newspec);
+ tree ret = build_string (newlen + 1, newspec);
+ if (newspec != attrspec)
+ XDELETEVEC (newspec);
+ return ret;
}
/* Handle the access attribute (read_only, write_only, and read_write). */
@@ -4168,7 +4175,8 @@ handle_access_attribute (tree *node, tree name, tree args,
{
/* Repeat for the previously declared type. */
attrs = TYPE_ATTRIBUTES (TREE_TYPE (node[1]));
- tree new_attrs = append_access_attrs (node[1], attrs, attrstr, code, idxs);
+ tree new_attrs
+ = append_access_attrs (node[1], attrs, attrstr, code, idxs);
if (!new_attrs)
return NULL_TREE;