This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] avoid using strnlen result for late calls to strlen (PR 82604)
- 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: Fri, 22 Jun 2018 16:00:41 -0600
- Subject: Re: [PATCH] avoid using strnlen result for late calls to strlen (PR 82604)
- References: <0997dcae-8ae2-27c0-45e9-fb110ecca2e6@gmail.com>
On 06/18/2018 01:15 PM, Martin Sebor wrote:
> While looking into opportunities to detect strnlen/strlen coding
> mistakes (pr86199) I noticed a bug in the strnlen implementation
> I committed earlier today that lets a strnlen() result be saved
> and used in subsequent calls to strlen() with the same argument.
> The attached patch changes the handle_builtin_strlen() function
> to discard the strnlen() result unless its bound is greater than
> the length of the string.
>
> Martin
>
> gcc-86204.diff
>
>
> PR tree-optimization/86204 - wrong strlen result after prior strnlen
>
> gcc/ChangeLog:
>
> PR tree-optimization/86204
> * tree-ssa-strlen.c (handle_builtin_strlen): Avoid storing
> a strnlen result if it's less than the length of the string.
>
> gcc/testsuite/ChangeLog:
>
> PR tree-optimization/86204
> * gcc.dg/strlenopt-46.c: New test.
OK. Though I must admit I don't like having variables "bounded" and
"bound" in the same function. So consider renaming one to avoid future
confusion.
jeff