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
This commit is contained in:
Jakub Jelinek 2019-11-23 11:06:26 +01:00 committed by Jakub Jelinek
parent ba585b9153
commit 1fbf51cb84
4 changed files with 24 additions and 5 deletions

View File

@ -1,5 +1,8 @@
2019-11-23 Jakub Jelinek <jakub@redhat.com> 2019-11-23 Jakub Jelinek <jakub@redhat.com>
PR middle-end/83859
* doc/extend.texi (attribute access): Fix a typo.
PR rtl-optimization/92610 PR rtl-optimization/92610
* cse.c (rest_of_handle_cse2): Call cleanup_cfg (0) also if * cse.c (rest_of_handle_cse2): Call cleanup_cfg (0) also if
cse_cfg_altered is set, even when tem is 0. cse_cfg_altered is set, even when tem is 0.

View File

@ -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> 2019-11-22 Jakub Jelinek <jakub@redhat.com>
PR c/90677 PR c/90677

View File

@ -3840,7 +3840,7 @@ append_access_attrs (tree t, tree attrs, const char *attrstr,
if (idxs[1]) if (idxs[1])
n2 = sprintf (attrspec + n1 + 1, "%u", (unsigned) idxs[1] - 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; char *newspec = attrspec;
if (tree acs = lookup_attribute ("access", attrs)) 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]) if (*attrspec != pos[-1])
{ {
/* Mismatch in access mode. */ /* Mismatch in access mode. */
auto_diagnostic_group d;
if (warning (OPT_Wattributes, if (warning (OPT_Wattributes,
"attribute %qs mismatch with mode %qs", "attribute %qs mismatch with mode %qs",
attrstr, attrstr,
@ -3884,6 +3885,7 @@ append_access_attrs (tree t, tree attrs, const char *attrstr,
if ((n2 && pos[n1 - 1] != ',')) if ((n2 && pos[n1 - 1] != ','))
{ {
/* Mismatch in the presence of the size argument. */ /* Mismatch in the presence of the size argument. */
auto_diagnostic_group d;
if (warning (OPT_Wattributes, if (warning (OPT_Wattributes,
"attribute %qs positional argument 2 conflicts " "attribute %qs positional argument 2 conflicts "
"with previous designation", "with previous designation",
@ -3897,6 +3899,7 @@ append_access_attrs (tree t, tree attrs, const char *attrstr,
if (!n2 && pos[n1 - 1] == ',') if (!n2 && pos[n1 - 1] == ',')
{ {
/* Mismatch in the presence of the size argument. */ /* Mismatch in the presence of the size argument. */
auto_diagnostic_group d;
if (warning (OPT_Wattributes, if (warning (OPT_Wattributes,
"attribute %qs missing positional argument 2 " "attribute %qs missing positional argument 2 "
"provided in previous designation", "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)) if (n2 && strncmp (attrstr + n1 + 1, pos + n1, n2))
{ {
/* Mismatch in the value of the size argument. */ /* Mismatch in the value of the size argument. */
auto_diagnostic_group d;
if (warning (OPT_Wattributes, if (warning (OPT_Wattributes,
"attribute %qs mismatch positional argument " "attribute %qs mismatch positional argument "
"values %i and %i", "values %i and %i",
@ -3929,7 +3933,7 @@ append_access_attrs (tree t, tree attrs, const char *attrstr,
attrspec[n1] = ','; attrspec[n1] = ',';
size_t len = strlen (str); size_t len = strlen (str);
newspec = (char *) xmalloc (newlen + len + 1); newspec = XNEWVEC (char, newlen + len + 1);
strcpy (newspec, str); strcpy (newspec, str);
strcpy (newspec + len, attrspec); strcpy (newspec + len, attrspec);
newlen += len; 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. */ /* Connect the two substrings formatted above into a single one. */
attrspec[n1] = ','; 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). */ /* 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. */ /* Repeat for the previously declared type. */
attrs = TYPE_ATTRIBUTES (TREE_TYPE (node[1])); 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) if (!new_attrs)
return NULL_TREE; return NULL_TREE;

View File

@ -2490,7 +2490,7 @@ The following attributes are supported on most targets.
The @code{access} attribute enables the detection of invalid or unsafe The @code{access} attribute enables the detection of invalid or unsafe
accesses by functions to which they apply to or their callers, as well 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}, may be diagnosed by warnings such as @option{-Wstringop-overflow},
@option{-Wunnitialized}, @option{-Wunused}, and others. @option{-Wunnitialized}, @option{-Wunused}, and others.