diff mbox series

[2/4] xfs_db: fix unitialized variable ifake->if_levels

Message ID 20240613181745.1052423-3-bodonnel@redhat.com (mailing list archive)
State New
Headers show
Series xfsprogs: coverity fixes | expand

Commit Message

Bill O'Donnell June 13, 2024, 6:07 p.m. UTC
Initialize if_levels to 0.

Coverity-id: 1596600, 1596597

Signed-off-by: Bill O'Donnell <bodonnel@redhat.com>
---
 db/bmap_inflate.c | 2 ++
 1 file changed, 2 insertions(+)

Comments

Christoph Hellwig June 13, 2024, 6:36 p.m. UTC | #1
On Thu, Jun 13, 2024 at 01:07:06PM -0500, Bill O'Donnell wrote:
> Initialize if_levels to 0.
> 
> Coverity-id: 1596600, 1596597
> 
> Signed-off-by: Bill O'Donnell <bodonnel@redhat.com>
> ---
>  db/bmap_inflate.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/db/bmap_inflate.c b/db/bmap_inflate.c
> index 33b0c954..8232f486 100644
> --- a/db/bmap_inflate.c
> +++ b/db/bmap_inflate.c
> @@ -351,6 +351,7 @@ build_new_datafork(
>  	/* Set up staging for the new bmbt */
>  	ifake.if_fork = kmem_cache_zalloc(xfs_ifork_cache, 0);
>  	ifake.if_fork_size = xfs_inode_fork_size(ip, XFS_DATA_FORK);
> +	ifake.if_levels = 0;
>  	bmap_cur = libxfs_bmbt_stage_cursor(ip->i_mount, ip, &ifake);
>  
>  	/*
> @@ -404,6 +405,7 @@ estimate_size(
>  
>  	ifake.if_fork = kmem_cache_zalloc(xfs_ifork_cache, 0);
>  	ifake.if_fork_size = xfs_inode_fork_size(ip, XFS_DATA_FORK);
> +	ifake.if_levels = 0;

Maybe initialize it at declaration time by doing:

	struct xbtree_ifakeroot		ifake = { };

to future-proof against adding more fields?
Bill O'Donnell June 13, 2024, 6:58 p.m. UTC | #2
On Thu, Jun 13, 2024 at 11:36:51AM -0700, Christoph Hellwig wrote:
> On Thu, Jun 13, 2024 at 01:07:06PM -0500, Bill O'Donnell wrote:
> > Initialize if_levels to 0.
> > 
> > Coverity-id: 1596600, 1596597
> > 
> > Signed-off-by: Bill O'Donnell <bodonnel@redhat.com>
> > ---
> >  db/bmap_inflate.c | 2 ++
> >  1 file changed, 2 insertions(+)
> > 
> > diff --git a/db/bmap_inflate.c b/db/bmap_inflate.c
> > index 33b0c954..8232f486 100644
> > --- a/db/bmap_inflate.c
> > +++ b/db/bmap_inflate.c
> > @@ -351,6 +351,7 @@ build_new_datafork(
> >  	/* Set up staging for the new bmbt */
> >  	ifake.if_fork = kmem_cache_zalloc(xfs_ifork_cache, 0);
> >  	ifake.if_fork_size = xfs_inode_fork_size(ip, XFS_DATA_FORK);
> > +	ifake.if_levels = 0;
> >  	bmap_cur = libxfs_bmbt_stage_cursor(ip->i_mount, ip, &ifake);
> >  
> >  	/*
> > @@ -404,6 +405,7 @@ estimate_size(
> >  
> >  	ifake.if_fork = kmem_cache_zalloc(xfs_ifork_cache, 0);
> >  	ifake.if_fork_size = xfs_inode_fork_size(ip, XFS_DATA_FORK);
> > +	ifake.if_levels = 0;
> 
> Maybe initialize it at declaration time by doing:
> 
> 	struct xbtree_ifakeroot		ifake = { };
> 
> to future-proof against adding more fields?
> 
Makes sense, I'll send a new version.
Thanks-
Bill
diff mbox series

Patch

diff --git a/db/bmap_inflate.c b/db/bmap_inflate.c
index 33b0c954..8232f486 100644
--- a/db/bmap_inflate.c
+++ b/db/bmap_inflate.c
@@ -351,6 +351,7 @@  build_new_datafork(
 	/* Set up staging for the new bmbt */
 	ifake.if_fork = kmem_cache_zalloc(xfs_ifork_cache, 0);
 	ifake.if_fork_size = xfs_inode_fork_size(ip, XFS_DATA_FORK);
+	ifake.if_levels = 0;
 	bmap_cur = libxfs_bmbt_stage_cursor(ip->i_mount, ip, &ifake);
 
 	/*
@@ -404,6 +405,7 @@  estimate_size(
 
 	ifake.if_fork = kmem_cache_zalloc(xfs_ifork_cache, 0);
 	ifake.if_fork_size = xfs_inode_fork_size(ip, XFS_DATA_FORK);
+	ifake.if_levels = 0;
 
 	bmap_cur = libxfs_bmbt_stage_cursor(ip->i_mount, ip, &ifake);
 	error = -libxfs_btree_bload_compute_geometry(bmap_cur, &bmap_bload,