This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] avoid bogus -Wstringop-overflow for strncpy with _FORTIFY_SOURCE (PR 82646)
- 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: Tue, 5 Dec 2017 16:51:17 -0700
- Subject: Re: [PATCH] avoid bogus -Wstringop-overflow for strncpy with _FORTIFY_SOURCE (PR 82646)
- Authentication-results: sourceware.org; auth=none
- References: <1e65b499-e816-4709-8e58-f591dea6508a@gmail.com>
On 12/05/2017 04:47 PM, Martin Sebor wrote:
> PR middle-end/82646 - bogus -Wstringop-overflow with
> -D_FORTIFY_SOURCE=2 on strncpy with range to a member array,
>
> The bug points out a false positive in a call to strncpy() when
> _FORTIFY_SOURCE is defined that doesn't exist otherwise.
>
> The problem is that __builtin_strncpy buffer overflow checking
> is done along with the expansion of the intrinsic in one place
> and __builtin___strncpy_chk is handled differently in another,
> and the two are out of sync.
>
> The attached patch corrects the choice of arguments used for
> overflow detection in __builtin___strncpy_chk and aligns
> the diagnostics between the two intrinsics.
>
> Martin
>
> gcc-82646.diff
>
>
> PR tree-optimization/82646 - bogus -Wstringop-overflow with -D_FORTIFY_SOURCE=2 on strncpy with range to a member array
>
> gcc/ChangeLog:
>
> PR tree-optimization/82646
> * builtins.c (maybe_emit_chk_warning): Use size as the bound for
> strncpy, not maxlen.
>
> gcc/testsuite/ChangeLog:
>
> PR tree-optimization/82646
> * gcc.dg/builtin-stringop-chk-1.c: Adjust.
> * gcc.dg/builtin-stringop-chk-9.c: New test.
OK.
[ Happy to see something easy fly by that isn't SVE related :-) ]
jeff