]> git.ipfire.org Git - thirdparty/openvpn.git/commitdiff
Fix various sign-compare warnings due to write return value
authorFrank Lichtenheld <frank@lichtenheld.com>
Fri, 6 Mar 2026 16:33:31 +0000 (17:33 +0100)
committerGert Doering <gert@greenie.muc.de>
Sat, 7 Mar 2026 09:08:17 +0000 (10:08 +0100)
write takes size_t as count (unsigned int on
Windows) and returns ssize_t (int on Windows).
But we often want to compare the return value
to the count.

Generally we can just rely on the fact that
sizeof(ssize_t) == sizeof(size_t) and use that
for all values. (Until we want to introduce
-Wsign-conversion that is...)

Change-Id: I3eb4581980f532cb2960b37a6fa43a7baee4b603
Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com>
Acked-by: Gert Doering <gert@greenie.muc.de>
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1513
Message-Id: <20260306163337.2756-1-gert@greenie.muc.de>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg35963.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
src/openvpn/ps.c
src/openvpn/status.c
src/plugins/auth-pam/auth-pam.c

index c589248e1036f6c9018a4f3d84052dde8ef2ce0f..c3f54ed25a8795fa71a78644dd32e5ba330b3c69 100644 (file)
@@ -327,11 +327,6 @@ proxy_list_housekeeping(struct proxy_connection **list)
     }
 }
 
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wsign-compare"
-#endif
-
 /*
  * Record IP/port of client in filesystem, so that server receiving
  * the proxy can determine true client origin.
@@ -357,7 +352,8 @@ journal_add(const char *journal_dir, struct proxy_connection *pc, struct proxy_c
         int fd = platform_open(jfn, O_CREAT | O_TRUNC | O_WRONLY, S_IRUSR | S_IWUSR | S_IRGRP);
         if (fd != -1)
         {
-            if (write(fd, f, strlen(f)) != strlen(f))
+            ssize_t write_len = strlen(f);
+            if (write(fd, f, write_len) != write_len)
             {
                 msg(M_WARN, "PORT SHARE: writing to journal file (%s) failed", jfn);
             }
@@ -373,10 +369,6 @@ journal_add(const char *journal_dir, struct proxy_connection *pc, struct proxy_c
     }
 }
 
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic pop
-#endif
-
 /*
  * Cleanup function, on proxy process exit.
  */
index 4d4286396b8d576968c958f018a475f08a4ff84b..c7d375b16149cf84884d188a25416a662fa8058f 100644 (file)
@@ -206,11 +206,6 @@ status_close(struct status_output *so)
     return ret;
 }
 
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wsign-compare"
-#endif
-
 #define STATUS_PRINTF_MAXLEN 512
 
 void
@@ -240,7 +235,7 @@ status_printf(struct status_output *so, const char *format, ...)
         if (so->fd >= 0 && !so->errors)
         {
             strcat(buf, "\n");
-            size_t len = strlen(buf);
+            ssize_t len = strlen(buf);
             if (len > 0)
             {
                 if (write(so->fd, buf, (unsigned int)len) != len)
@@ -258,10 +253,6 @@ status_printf(struct status_output *so, const char *format, ...)
     }
 }
 
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic pop
-#endif
-
 bool
 status_read(struct status_output *so, struct buffer *buf)
 {
index 0f3346f0bdd8a53b4dbc7b2b96a97505b5c9dee7..3b7bcc29f6656ad61affcf9d397258362630faa1 100644 (file)
@@ -184,15 +184,10 @@ recv_string(int fd, char *buffer, size_t len)
     return -1;
 }
 
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wsign-compare"
-#endif
-
 static ssize_t
 send_string(int fd, const char *string)
 {
-    const size_t len = strlen(string) + 1;
+    const ssize_t len = strlen(string) + 1;
     const ssize_t size = write(fd, string, len);
     if (size == len)
     {
@@ -204,10 +199,6 @@ send_string(int fd, const char *string)
     }
 }
 
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic pop
-#endif
-
 #ifdef DO_DAEMONIZE
 
 /*