diff mbox series

xfs_scrub: Use POSIX-conformant strerror_r

Message ID 20240811025104.54614-1-AWilcox@Wilcox-Tech.com (mailing list archive)
State Accepted, archived
Headers show
Series xfs_scrub: Use POSIX-conformant strerror_r | expand

Commit Message

A. Wilcox Aug. 11, 2024, 2:51 a.m. UTC
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.

Signed-off-by: A. Wilcox <AWilcox@Wilcox-Tech.com>
---
 scrub/common.c | 3 ++-
 scrub/inodes.c | 4 ++--
 2 files changed, 4 insertions(+), 3 deletions(-)

Comments

Christoph Hellwig Aug. 11, 2024, 8:42 a.m. UTC | #1
> +++ b/scrub/inodes.c
> @@ -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.
diff mbox series

Patch

diff --git a/scrub/common.c b/scrub/common.c
index 283ac84e..bd8bde35 100644
--- a/scrub/common.c
+++ b/scrub/common.c
@@ -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);
diff --git a/scrub/inodes.c b/scrub/inodes.c
index 16c79cf4..f0e7289c 100644
--- a/scrub/inodes.c
+++ b/scrub/inodes.c
@@ -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);
 	}
 
 	/*