This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH 1/4] enhance overflow and truncation detection in strncpy and strncat (PR 81117)
- From: Jeff Law <law at redhat dot com>
- To: Martin Sebor <msebor at gmail dot com>, Gcc Patch List <gcc-patches at gcc dot gnu dot org>
- Date: Wed, 9 Aug 2017 22:44:14 -0600
- Subject: Re: [PATCH 1/4] enhance overflow and truncation detection in strncpy and strncat (PR 81117)
- Authentication-results: sourceware.org; auth=none
- Authentication-results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com
- Authentication-results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=law at redhat dot com
- Dmarc-filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 46D3336FAC2
- References: <13944863-99a8-4144-1703-c6e1a2f36425@gmail.com> <0bbc91cd-fcdb-be61-e1d0-4b230f23b1a9@redhat.com> <4f4fbd4c-cb46-b80d-5749-ebb6bb050bc4@gmail.com> <a0069a6d-d4a8-67df-e2f3-902dc7704ab2@redhat.com> <33a2ba18-274d-8229-06b4-c4983f0d3e2f@gmail.com>
On 08/06/2017 02:07 PM, Martin Sebor wrote:
> The attached patch adds support for a new GCC format specifier,
> G, that behaves like %K but accepts a gcall* argument. This
> makes it possible to provide inlining context for "artificial"
> inline functions like strncpy (with _FORTIFY_SOURCE) in
> diagnostics issued from the middle end.
>
> Martin
>
> gcc-81117-1.diff
>
>
> PR c/81117 - Improve buffer overflow checking in strncpy
>
> gcc/ChangeLog:
>
> PR c/81117
> * tree-diagnostic.c (default_tree_printer): Handle %G.
> * tree-pretty-print.h (percent_G_format): Declare new function.
> * tree-pretty-print.c (percent_K_format): Define a static overload.
> (percent_G_format): New function.
>
> gcc/c/ChangeLog:
>
> PR c/81117
> * c-objc-common.c (c_objc_common_init): Handle 'G'.
>
> gcc/c-family/ChangeLog:
>
> * c-format.h (T89_G): New macro.
> * c-format.c (local_gcall_ptr_node): New variable.
> (init_dynamic_diag_info): Initialize it.
>
> gcc/cp/ChangeLog:
>
> PR c/81117
> * error.c (cp_printer): Handle 'G'.
>
> gcc/testsuite/ChangeLog:
>
> PR c/81117
> * gcc.dg/format/gcc_diag-10.c: Exercise %G.
>
> diff --git a/gcc/tree-diagnostic.c b/gcc/tree-diagnostic.c
> index 52b7e7f..ad58b69 100644
> --- a/gcc/tree-diagnostic.c
> +++ b/gcc/tree-diagnostic.c
> @@ -275,6 +275,10 @@ default_tree_printer (pretty_printer *pp, text_info *text, const char *spec,
> t = va_arg (*text->args_ptr, tree);
> break;
>
> + case 'G':
> + percent_G_format (text);
> + return true;
> +
> case 'K':
> percent_K_format (text);
> return true;
> diff --git a/gcc/tree-pretty-print.c b/gcc/tree-pretty-print.c
> index 4d8177c..7c4c805 100644
> --- a/gcc/tree-pretty-print.c
> +++ b/gcc/tree-pretty-print.c
> @@ -33,6 +33,7 @@ along with GCC; see the file COPYING3. If not see
> #include "dumpfile.h"
> #include "internal-fn.h"
> #include "gomp-constants.h"
> +#include "gimple.h"
This is an indication you're probably putting the 'G' handling in the
wrong place. Wouldn't gimple-pretty-print.c be more correct?
That's my only objection to this patch, so if it moves trivially, then
it's pre-approved. If it's non-trivial, then we'll want another iteration.
jeff