Skip to contentSkip to conversation

xfs_scrub: Use POSIX-conformant strerror_r

PATCH In review A. Wilcox 2 participants 2 messages Aug 11, 2024

lore
Share & tools
lore

A. Wilcox

author
#0 lore raw

PATCH 1/1 xfs_scrub: Use POSIX-conformant strerror_r

When building xfsprogs with musl libc, strerror_r returns int as specified in POSIX. This differs from the glibc extension that returns char*. Successful calls will return 0, which will be dereferenced as a NULL pointer by (v)fprintf.

---
 scrub/common.c | 3 ++-
 scrub/inodes.c | 4 ++--
 2 files changed, 4 insertions(+), 3 deletions(-)
scrub/common.c +2 -1
index 283ac84e..bd8bde35 100644
@@ -122,7 +122,8 @@ __str_out(
 	fprintf(stream, "%s%s: %s: ", stream_start(stream),
 			_(err_levels[level].string), descr);
 	if (error) {
-		fprintf(stream, _("%s."), strerror_r(error, buf, DESCR_BUFSZ));
+		strerror_r(error, buf, DESCR_BUFSZ);
+		fprintf(stream, _("%s."), buf);
 	} else {
 		va_start(args, format);
 		vfprintf(stream, format, args);
scrub/inodes.c +2 -2
index 16c79cf4..f0e7289c 100644
@@ -65,9 +65,9 @@ bulkstat_for_inumbers(
 	error = -xfrog_bulkstat(&ctx->mnt, breq);
 	if (error) {
 		char	errbuf[DESCR_BUFSZ];
+		strerror_r(error, errbuf, DESCR_BUFSZ);
 
-		str_info(ctx, descr_render(dsc), "%s",
-			 strerror_r(error, errbuf, DESCR_BUFSZ));
+		str_info(ctx, descr_render(dsc), "%s", errbuf);
 	}
 
 	/*
Signature · 1 line
2.40.0
#1 lore raw

scrub/inodes.c bulkstat_for_inumbers( · line 70

Quoted 10 lines

+++ b/scrub/inodes.c

scrub/inodes.c +2 -2
@@ -65,9 +65,9 @@ bulkstat_for_inumbers(
 	error = -xfrog_bulkstat(&ctx->mnt, breq);
 	if (error) {
 		char	errbuf[DESCR_BUFSZ];
+		strerror_r(error, errbuf, DESCR_BUFSZ);
 
-		str_info(ctx, descr_render(dsc), "%s",
-			 strerror_r(error, errbuf, DESCR_BUFSZ));
+		str_info(ctx, descr_render(dsc), "%s", errbuf);

Please keep an empty line after the variable declaration. I'd skip the one between the strerror_r and str_info calls instead, though.

Otherwise this looks good to me.