ftw.c: strchr(s, '\0') isn't always optimized to s + strlen(s)

Message ID 20230925081925.81343-1-tirtajames45@gmail.com
State Dropped
Headers
Series ftw.c: strchr(s, '\0') isn't always optimized to s + strlen(s) |

Checks

Context Check Description
redhat-pt-bot/TryBot-apply_patch success Patch applied to master at the time it was sent
redhat-pt-bot/TryBot-32bit fail Patch series failed to build
linaro-tcwg-bot/tcwg_glibc_check--master-arm fail Testing failed
linaro-tcwg-bot/tcwg_glibc_build--master-aarch64 fail Testing failed
linaro-tcwg-bot/tcwg_glibc_check--master-aarch64 fail Testing failed
linaro-tcwg-bot/tcwg_glibc_build--master-arm fail Testing failed

Commit Message

James Tirta Halim Sept. 25, 2023, 8:19 a.m. UTC
  ---
 io/ftw.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
  

Comments

Cristian Rodríguez Sept. 25, 2023, 11:57 a.m. UTC | #1
On Mon, Sep 25, 2023 at 5:23 AM James Tirta Halim <tirtajames45@gmail.com>
wrote:

> ---
>  io/ftw.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/io/ftw.c b/io/ftw.c
> index 742369a2d2..533b4012e5 100644
> --- a/io/ftw.c
> +++ b/io/ftw.c
> @@ -554,7 +554,7 @@ fail:
>
>    /* Next, update the `struct FTW' information.  */
>    ++data->ftw.level;
> -  startp = strchr (data->dirbuf, '\0');
> +  startp = data->dirbuf + strlen(data->dirbuf):
>    /* There always must be a directory name.  */
>    assert (startp != data->dirbuf);
>    if (startp[-1] != '/')
> @@ -595,7 +595,7 @@ fail:
>
>        while (result == 0 && *runp != '\0')
>         {
> -         char *endp = strchr (runp, '\0');
> +         char *endp = runp + strlen(runp);
>
>           // XXX Should store the d_type values as well?!
>           result = process_entry (data, &dir, runp, endp - runp,
> DT_UNKNOWN);
> --
> 2.42.0
>
>
Did you fill out a compiler enhancement request ?  AFAIK it should always
do this transformation..(unless I'm missing an special case)
  

Patch

diff --git a/io/ftw.c b/io/ftw.c
index 742369a2d2..533b4012e5 100644
--- a/io/ftw.c
+++ b/io/ftw.c
@@ -554,7 +554,7 @@  fail:
 
   /* Next, update the `struct FTW' information.  */
   ++data->ftw.level;
-  startp = strchr (data->dirbuf, '\0');
+  startp = data->dirbuf + strlen(data->dirbuf):
   /* There always must be a directory name.  */
   assert (startp != data->dirbuf);
   if (startp[-1] != '/')
@@ -595,7 +595,7 @@  fail:
 
       while (result == 0 && *runp != '\0')
 	{
-	  char *endp = strchr (runp, '\0');
+	  char *endp = runp + strlen(runp);
 
 	  // XXX Should store the d_type values as well?!
 	  result = process_entry (data, &dir, runp, endp - runp, DT_UNKNOWN);