[PATCH] silence unused results warnings from compilers

Mike Frysinger vapier@gentoo.org
Sun Apr 11 15:07:37 GMT 2021


Newer C libraries mark these funcs with warn_unused_result, and newer
compilers use that to emit warnings.  The classic (void) cast is not
sufficient either.  Put them into an if() check with an empty body.
---
 bzip2.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/bzip2.c b/bzip2.c
index d1f2fa85357c..0f3adfbc3428 100644
--- a/bzip2.c
+++ b/bzip2.c
@@ -854,6 +854,8 @@ void mySIGSEGVorSIGBUScatcher ( IntNative n )
       "   system, please try and read it before mailing me.  If you don't\n"
       "   have the manual or can't be bothered to read it, mail me anyway.\n"
       "\n";
+   /* Ignore any errors from write. Not much we can do here. */
+#define write(...) if (write(__VA_ARGS__)) {}
    write ( STDERR_FILENO, "\n", 1 );
    write ( STDERR_FILENO, progName, strlen ( progName ) );
    write ( STDERR_FILENO, msg, strlen ( msg ) );
@@ -866,6 +868,7 @@ void mySIGSEGVorSIGBUScatcher ( IntNative n )
    write ( STDERR_FILENO, msg, strlen (msg) );
    write ( STDERR_FILENO, outName, strlen (outName) );
    write ( STDERR_FILENO, "\n", 1 );
+#undef write
 
    /* Don't call cleanupAndFail. If we ended up here something went
       terribly wrong. Trying to clean up might fail spectacularly. */
@@ -1078,10 +1081,11 @@ void applySavedFileAttrToOutputFile ( IntNative fd )
    retVal = fchmod ( fd, fileMetaInfo.st_mode );
    ERROR_IF_NOT_ZERO ( retVal );
 
-   (void) fchown ( fd, fileMetaInfo.st_uid, fileMetaInfo.st_gid );
-   /* chown() will in many cases return with EPERM, which can
-      be safely ignored.
-   */
+   if (fchown ( fd, fileMetaInfo.st_uid, fileMetaInfo.st_gid )) {
+     /* chown() will in many cases return with EPERM, which can
+        be safely ignored.
+     */
+   }
 #  endif
 }
 
-- 
2.30.2



More information about the Bzip2-devel mailing list