xfs_scrub: Use POSIX-conformant strerror_r
PATCH v2 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 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
scrub/common.c +2 -1
@@ -126,7 +126,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);
Signature · 1 line
2.49.0
Looks good:
Quoted 6 lines · A. Wilcox
When building xfsprogs with musl libc,
strerror_rreturns 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 <[email protected]>
Isn't C fun?
--D
Quoted 22 lines
--- scrub/common.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)scrub/common.c +2
-1@@ -126,7 +126,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);Signature · 1 line
2.49.0
Quoted 10 lines · Darrick J. Wong
Quoted 6 lines · A. Wilcox
When building xfsprogs with musl libc,
strerror_rreturns 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 <[email protected]>Isn't C fun?
Reviewed-by "Darrick J. Wong" <[email protected]>
Ohh yes it is, this patch broke the build for me:
common.c: In function ‘__str_out’:
common.c:129:17: error: ignoring return value of ‘strerror_r’ declared with attribute ‘warn_unused_result’ [-Werror=unused-result]
129 | strerror_r(error, buf, DESCR_BUFSZ);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<sigh> xfsprogs can't get the XSI version because it defines GNU_SOURCE, and you can't shut up gcc by casting the whole expression to void.
Do you folks remove the -D_GNU_SOURCE from builddefs.in when building against musl? Or do you leave the definition alone, taking advantage of the fact that #define'ing a symbol is not a guarantee of functionality?
--D
Quoted 25 lines
--D
Quoted 22 lines
--- scrub/common.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)scrub/common.c +2
-1@@ -126,7 +126,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);Signature · 1 line
2.49.0
Quoted 7 lines · Darrick J. Wong
Quoted 6 lines · Darrick J. Wong
Quoted 5 lines · A. Wilcox
When building xfsprogs with musl libc,
strerror_rreturns 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.
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
Signed-off-by A. Wilcox <[email protected]>Isn't C fun?
Reviewed-by "Darrick J. Wong" <[email protected]>Ohh yes it is, this patch broke the build for me:
do you build gcc + musl?
- Andrey
Quoted 41 lines
common.c: In function ‘__str_out’:
common.c:129:17: error: ignoring return value of ‘strerror_r’ declared with attribute ‘warn_unused_result’ [-Werror=unused-result]129 | strerror_r(error, buf, DESCR_BUFSZ); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<sigh> xfsprogs can't get the XSI version because it defines
GNU_SOURCE, and you can't shut up gcc by casting the whole expression to void.Do you folks remove the -D_GNU_SOURCE from builddefs.in when building against musl? Or do you leave the definition alone, taking advantage of the fact that #define'ing a symbol is not a guarantee of functionality?
--D
Quoted 25 lines
--D
Quoted 22 lines
--- scrub/common.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)scrub/common.c +2
-1@@ -126,7 +126,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);Signature · 1 line
2.49.0
Quoted 8 lines · Andrey Albershteyn
Quoted 7 lines · Darrick J. Wong
Quoted 6 lines · Darrick J. Wong
Quoted 5 lines · A. Wilcox
When building xfsprogs with musl libc,
strerror_rreturns 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.
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
Signed-off-by A. Wilcox <[email protected]>Isn't C fun?
Reviewed-by "Darrick J. Wong" <[email protected]>Ohh yes it is, this patch broke the build for me:
do you build gcc + musl?
I don't even know /how/ to do that, even on Debian.
--D
Quoted 45 lines
- Andrey
Quoted 41 lines
common.c: In function ‘__str_out’:
common.c:129:17: error: ignoring return value of ‘strerror_r’ declared with attribute ‘warn_unused_result’ [-Werror=unused-result]129 | strerror_r(error, buf, DESCR_BUFSZ); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<sigh> xfsprogs can't get the XSI version because it defines
GNU_SOURCE, and you can't shut up gcc by casting the whole expression to void.Do you folks remove the -D_GNU_SOURCE from builddefs.in when building against musl? Or do you leave the definition alone, taking advantage of the fact that #define'ing a symbol is not a guarantee of functionality?
--D
Quoted 25 lines
--D
Quoted 22 lines
--- scrub/common.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)scrub/common.c +2
-1@@ -126,7 +126,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);Signature · 1 line
2.49.0