public inbox for linux-xfs@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] xfs_io: fix gcc complaints about potentially uninitialized variables
@ 2024-05-31 20:12 Darrick J. Wong
  2024-06-01  5:02 ` Christoph Hellwig
  0 siblings, 1 reply; 2+ messages in thread
From: Darrick J. Wong @ 2024-05-31 20:12 UTC (permalink / raw)
  To: Carlos Maiolino; +Cc: xfs

From: Darrick J. Wong <djwong@kernel.org>

When I turned on UBSAN on the userspace build with gcc 12.2, I get this:

bulkstat.c: In function ‘bulkstat_single_f’:
bulkstat.c:316:24: error: ‘ino’ may be used uninitialized [-Werror=maybe-uninitialized]
  316 |                 ret = -xfrog_bulkstat_single(&xfd, ino, flags, &bulkstat);
      |                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bulkstat.c:293:41: note: ‘ino’ was declared here
  293 |                 uint64_t                ino;
      |                                         ^~~

I /think/ this is a failure of the gcc static checker to notice that sm
will always be set to the last element of the tags[] array if it didn't
set ino, but this code could be more explicit about deciding to
fallback to strtoul.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
---
 io/bulkstat.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/io/bulkstat.c b/io/bulkstat.c
index 829f6a025153..f312c6d55f47 100644
--- a/io/bulkstat.c
+++ b/io/bulkstat.c
@@ -301,7 +301,7 @@ bulkstat_single_f(
 
 	for (i = optind; i < argc; i++) {
 		struct single_map	*sm = tags;
-		uint64_t		ino;
+		uint64_t		ino = NULLFSINO;
 		unsigned int		flags = 0;
 
 		/* Try to look up our tag... */
@@ -314,7 +314,7 @@ bulkstat_single_f(
 		}
 
 		/* ...or else it's an inode number. */
-		if (sm->tag == NULL) {
+		if (ino == NULLFSINO) {
 			errno = 0;
 			ino = strtoull(argv[i], NULL, 10);
 			if (errno) {

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] xfs_io: fix gcc complaints about potentially uninitialized variables
  2024-05-31 20:12 [PATCH] xfs_io: fix gcc complaints about potentially uninitialized variables Darrick J. Wong
@ 2024-06-01  5:02 ` Christoph Hellwig
  0 siblings, 0 replies; 2+ messages in thread
From: Christoph Hellwig @ 2024-06-01  5:02 UTC (permalink / raw)
  To: Darrick J. Wong; +Cc: Carlos Maiolino, xfs

Looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-06-01  5:02 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-05-31 20:12 [PATCH] xfs_io: fix gcc complaints about potentially uninitialized variables Darrick J. Wong
2024-06-01  5:02 ` Christoph Hellwig

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox