[i-g-t,1/7] Remove parameter aliases with another argument
diff mbox

Message ID 1fdd00077524f8c4703095a67caa3d0f920e3c05.1531005542.git.rodrigosiqueiramelo@gmail.com
State New
Headers show

Commit Message

Rodrigo Siqueira July 7, 2018, 11:22 p.m. UTC
This commit fixes the following GCC warning:

warning: passing argument 2 to restrict-qualified parameter aliases with
argument 1 [-Wrestrict]
  return (readlink (buf, buf, sizeof (buf)) != -1 &&

This commit fixes the GCC warning by creating a second buffer only to
keep the path.

Signed-off-by: Rodrigo Siqueira <rodrigosiqueiramelo@gmail.com>
---
 lib/igt_core.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

Comments

Arkadiusz Hiler July 10, 2018, 1:50 p.m. UTC | #1
On Sat, Jul 07, 2018 at 08:22:25PM -0300, Rodrigo Siqueira wrote:
> This commit fixes the following GCC warning:
> 
> warning: passing argument 2 to restrict-qualified parameter aliases with
> argument 1 [-Wrestrict]
>   return (readlink (buf, buf, sizeof (buf)) != -1 &&
> 
> This commit fixes the GCC warning by creating a second buffer only to
> keep the path.
> 
> Signed-off-by: Rodrigo Siqueira <rodrigosiqueiramelo@gmail.com>
> ---
>  lib/igt_core.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/lib/igt_core.c b/lib/igt_core.c
> index 3313050c..fa22f12d 100644
> --- a/lib/igt_core.c
> +++ b/lib/igt_core.c
> @@ -1169,10 +1169,10 @@ bool igt_can_fail(void)
>  
>  static bool run_under_gdb(void)
>  {
> -	char buf[1024];
> +	char pathname[1024], buf[1024];

1024 for pathname is quite an overshoot. We stash at most
"/proc/%d/exec" where %d should be at most 21 or so.

> -	sprintf(buf, "/proc/%d/exe", getppid());
> -	return (readlink (buf, buf, sizeof (buf)) != -1 &&
> +	sprintf(pathname, "/proc/%d/exe", getppid());
> +	return (readlink (pathname, buf, sizeof (buf)) != -1 &&

                        ^ while we are here we can get rid of that space

>  		strncmp(basename(buf), "gdb", 3) == 0);
>  }
>  
> -- 
> 2.18.0
>

Patch
diff mbox

diff --git a/lib/igt_core.c b/lib/igt_core.c
index 3313050c..fa22f12d 100644
--- a/lib/igt_core.c
+++ b/lib/igt_core.c
@@ -1169,10 +1169,10 @@  bool igt_can_fail(void)
 
 static bool run_under_gdb(void)
 {
-	char buf[1024];
+	char pathname[1024], buf[1024];
 
-	sprintf(buf, "/proc/%d/exe", getppid());
-	return (readlink (buf, buf, sizeof (buf)) != -1 &&
+	sprintf(pathname, "/proc/%d/exe", getppid());
+	return (readlink (pathname, buf, sizeof (buf)) != -1 &&
 		strncmp(basename(buf), "gdb", 3) == 0);
 }