diff mbox series

fsstress: fix bogus compile warning do_renameat2()

Message ID 20210921175059.1287420-1-mcgrof@kernel.org (mailing list archive)
State New, archived
Headers show
Series fsstress: fix bogus compile warning do_renameat2() | expand

Commit Message

Luis Chamberlain Sept. 21, 2021, 5:50 p.m. UTC
gcc complains with:

fsstress.c:4629:4: warning: 'oldparid' may be used uninitialized in this function [-Wmaybe-uninitialized]
 4629 |    printf("%d/%d: rename source entry: id=%d,parent=%d\n",
      |    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 4630 |     procid, opno, oldid, oldparid);
      |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
fsstress.c:4629:4: warning: 'oldid' may be used uninitialized in this function [-Wmaybe-uninitialized]

But the varaibles are sure to be initialized, it is just that the
heuristics are broken since another check is used later which confuses
gcc. So just initialize the variables, to shup the compile warning.

Cc: kaixuxia <kaixuxia@tencent.com>
Cc: Brian Foster <bfoster@redhat.com>
Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
---
 ltp/fsstress.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Brian Foster Sept. 22, 2021, 5:24 p.m. UTC | #1
On Tue, Sep 21, 2021 at 10:50:59AM -0700, Luis Chamberlain wrote:
> gcc complains with:
> 
> fsstress.c:4629:4: warning: 'oldparid' may be used uninitialized in this function [-Wmaybe-uninitialized]
>  4629 |    printf("%d/%d: rename source entry: id=%d,parent=%d\n",
>       |    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>  4630 |     procid, opno, oldid, oldparid);
>       |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> fsstress.c:4629:4: warning: 'oldid' may be used uninitialized in this function [-Wmaybe-uninitialized]
> 
> But the varaibles are sure to be initialized, it is just that the
> heuristics are broken since another check is used later which confuses
> gcc. So just initialize the variables, to shup the compile warning.
> 

https://www.urbandictionary.com/define.php?term=shup

Huh. :P

> Cc: kaixuxia <kaixuxia@tencent.com>
> Cc: Brian Foster <bfoster@redhat.com>
> Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
> ---

Reviewed-by: Brian Foster <bfoster@redhat.com>

>  ltp/fsstress.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/ltp/fsstress.c b/ltp/fsstress.c
> index d2f09901..0d620d7b 100644
> --- a/ltp/fsstress.c
> +++ b/ltp/fsstress.c
> @@ -4517,9 +4517,9 @@ do_renameat2(int opno, long r, int mode)
>  	flist_t		*flp;
>  	int		id;
>  	pathname_t	newf;
> -	int		oldid;
> +	int		oldid = 0;
>  	int		parid;
> -	int		oldparid;
> +	int		oldparid = 0;
>  	int		which;
>  	int		v;
>  	int		v1;
> -- 
> 2.30.2
>
diff mbox series

Patch

diff --git a/ltp/fsstress.c b/ltp/fsstress.c
index d2f09901..0d620d7b 100644
--- a/ltp/fsstress.c
+++ b/ltp/fsstress.c
@@ -4517,9 +4517,9 @@  do_renameat2(int opno, long r, int mode)
 	flist_t		*flp;
 	int		id;
 	pathname_t	newf;
-	int		oldid;
+	int		oldid = 0;
 	int		parid;
-	int		oldparid;
+	int		oldparid = 0;
 	int		which;
 	int		v;
 	int		v1;