This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] avoid bogus -Wstringop-overflow for strncpy with _FORTIFY_SOURCE (PR 82646)


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]