From 1fbf51cb84cb1000fac324ef11554c36084cd537 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Sat, 23 Nov 2019 11:06:26 +0100 Subject: [PATCH] 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 --- gcc/ChangeLog | 3 +++ gcc/c-family/ChangeLog | 8 ++++++++ gcc/c-family/c-attribs.c | 16 ++++++++++++---- gcc/doc/extend.texi | 2 +- 4 files changed, 24 insertions(+), 5 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 596db034dfe..e5741316747 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,5 +1,8 @@ 2019-11-23 Jakub Jelinek + PR middle-end/83859 + * doc/extend.texi (attribute access): Fix a typo. + PR rtl-optimization/92610 * cse.c (rest_of_handle_cse2): Call cleanup_cfg (0) also if cse_cfg_altered is set, even when tem is 0. diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog index 1cf0fef5465..281d7f409b7 100644 --- a/gcc/c-family/ChangeLog +++ b/gcc/c-family/ChangeLog @@ -1,3 +1,11 @@ +2019-11-23 Jakub Jelinek + + 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 PR c/90677 diff --git a/gcc/c-family/c-attribs.c b/gcc/c-family/c-attribs.c index e307160a453..cc006f38366 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; diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi index 3a63d48f857..56a3d60a947 100644 --- a/gcc/doc/extend.texi +++ b/gcc/doc/extend.texi @@ -2490,7 +2490,7 @@ The following attributes are supported on most targets. The @code{access} attribute enables the detection of invalid or unsafe accesses by functions to which they apply to or their callers, as well -as wite-only accesses to objects that are never read from. Such accesses +as write-only accesses to objects that are never read from. Such accesses may be diagnosed by warnings such as @option{-Wstringop-overflow}, @option{-Wunnitialized}, @option{-Wunused}, and others.