bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

login_tty tests: Avoid gcc warnings


From: Bruno Haible
Subject: login_tty tests: Avoid gcc warnings
Date: Sat, 27 Apr 2024 02:25:28 +0200

Compiling a testdir on Ubuntu 24.04, I see these gcc 13.2 warnings:

../../gltests/test-login_tty.c:66:11: warning: ignoring return value of 
'freopen' declared with attribute 'warn_unused_result' [-Wunused-result]
../../gltests/test-login_tty.c:79:17: warning: ignoring return value of 
'freopen' declared with attribute 'warn_unused_result' [-Wunused-result]
../../gltests/test-login_tty.c:90:17: warning: ignoring return value of 
'freopen' declared with attribute 'warn_unused_result' [-Wunused-result]

This patch fixes them. The module 'ignore-value' is needed, since a simple
cast to void has no effect on the warnings.


2024-04-26  Bruno Haible  <bruno@clisp.org>

        login_tty tests: Avoid gcc warnings.
        * tests/test-login_tty.c: Include ignore-value.h.
        (main): Ignore the results of the freopen calls.
        * modules/login_tty-tests (Depends-on): Add ignore-value.

diff --git a/modules/login_tty-tests b/modules/login_tty-tests
index 306b0ebe12..aaad143c10 100644
--- a/modules/login_tty-tests
+++ b/modules/login_tty-tests
@@ -4,6 +4,7 @@ tests/test-login_tty.c
 Depends-on:
 openpty
 tcgetsid
+ignore-value
 
 configure.ac:
 
diff --git a/tests/test-login_tty.c b/tests/test-login_tty.c
index 6f3b25c6d4..ac3b405893 100644
--- a/tests/test-login_tty.c
+++ b/tests/test-login_tty.c
@@ -26,6 +26,8 @@
 #include <termios.h>
 #include <unistd.h>
 
+#include "ignore-value.h"
+
 int
 main ()
 {
@@ -63,7 +65,7 @@ main ()
     for (fd = 0; fd < 3; fd++)
       if (!(tcgetpgrp (fd) == getpid ()))
         {
-          freopen ("err", "w+", stderr);
+          ignore_value (freopen ("err", "w+", stderr));
           fprintf (stderr, "tcgetpgrp(%d) = %ld whereas getpid() = %ld\n",
                    fd, (long) tcgetpgrp (fd), (long) getpid ());
           fflush (stderr);
@@ -76,7 +78,7 @@ main ()
           {
             if (!(errno == ENOSYS))
               {
-                freopen ("err", "w+", stderr);
+                ignore_value (freopen ("err", "w+", stderr));
                 fprintf (stderr, "tcgetsid(%d) = -1 and errno = %d\n",
                          fd, errno);
                 fflush (stderr);
@@ -87,7 +89,7 @@ main ()
           {
             if (!(sid == getpid ()))
               {
-                freopen ("err", "w+", stderr);
+                ignore_value (freopen ("err", "w+", stderr));
                 fprintf (stderr, "tcgetsid(%d) = %ld whereas getpid() = %ld\n",
                          fd, (long) tcgetsid (fd), (long) getpid ());
                 fflush (stderr);






reply via email to

[Prev in Thread] Current Thread [Next in Thread]