Skip to contentSkip to conversation

Change in openvpn[master]: Fix various sign-compare warnings due to write return value

Openvpn-devel In review flichtenheld (Code Review) 2 participants 6 messages Feb 10 – Mar 7 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): gerrit.1770735307000.I3eb4581980f532cb2960b37a6fa43a7baee4b603@...2715...

#1 lore raw

Attention is currently required from: plaisthos.

Hello plaisthos,

I'd like you to do a code review.
Please visit

    http://gerrit.openvpn.net/c/openvpn/+/1513?usp=email

to review the following change.

Change subject: Fix various sign-compare warnings due to write return value
......................................................................

Fix various sign-compare warnings due to write return value

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

---
M src/openvpn/ps.c
M src/openvpn/status.c
M src/plugins/auth-pam/auth-pam.c

3 files changed, 4 insertions(+), 30 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/13/1513/1

src/openvpn/ps.c +2 -10
index e98502d..15816a5 100644
@@ -327,11 +327,6 @@
     }
 }
 
-#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 @@
         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 @@
     }
 }
 
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic pop
-#endif
-
 /*
  * Cleanup function, on proxy process exit.
  */
src/openvpn/status.c +1 -10
index 4d42863..c7d375b 100644
@@ -206,11 +206,6 @@
     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 @@
         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 @@
     }
 }
 
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic pop
-#endif
-
 bool
 status_read(struct status_output *so, struct buffer *buf)
 {
src/plugins/auth-pam/auth-pam.c +1 -10
index 0f3346f..3b7bcc2 100644
@@ -184,15 +184,10 @@
     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 @@
     }
 }
 
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic pop
-#endif
-
 #ifdef DO_DAEMONIZE
 
 /*

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1513?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: newchange
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I3eb4581980f532cb2960b37a6fa43a7baee4b603
Gerrit-Change-Number: 1513
Gerrit-PatchSet: 1
Gerrit-Owner: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>

#2 lore raw
In reply to a message not in the archive

Attention is currently required from: flichtenheld, plaisthos.

cron2 has posted comments on this change by flichtenheld. ( http://gerrit.openvpn.net/c/openvpn/+/1513?usp=email )

Change subject: Fix various sign-compare warnings due to write return value
......................................................................

Patch Set 3: Code-Review+2

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1513?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: comment
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I3eb4581980f532cb2960b37a6fa43a7baee4b603
Gerrit-Change-Number: 1513
Gerrit-PatchSet: 3
Gerrit-Owner: flichtenheld <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Comment-Date: Fri, 06 Mar 2026 16:33:24 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes

#3 lore raw

PATCH v3 1/1 Fix various sign-compare warnings due to write return value

In reply to a message not in the archive

From: Frank Lichtenheld <[email protected]...>

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

Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1513
---

This change was reviewed on Gerrit and approved by at least one developer. I request to merge it to master.

Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1513
This mail reflects revision 3 of this Change.

Acked-by according to Gerrit (reflected above):
Gert Doering <[email protected]...>

src/openvpn/ps.c +2 -10
index c589248..c3f54ed 100644
@@ -327,11 +327,6 @@
     }
 }
 
-#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 @@
         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 @@
     }
 }
 
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic pop
-#endif
-
 /*
  * Cleanup function, on proxy process exit.
  */
src/openvpn/status.c +1 -10
index 4d42863..c7d375b 100644
@@ -206,11 +206,6 @@
     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 @@
         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 @@
     }
 }
 
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic pop
-#endif
-
 bool
 status_read(struct status_output *so, struct buffer *buf)
 {
src/plugins/auth-pam/auth-pam.c +1 -10
index 0f3346f..3b7bcc2 100644
@@ -184,15 +184,10 @@
     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 @@
     }
 }
 
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic pop
-#endif
-
 #ifdef DO_DAEMONIZE
 
 /*
#4 lore raw

[Openvpn-devel] [PATCH applied] Re: Fix various sign-compare warnings due to write return value

While I do have some question about this and -Wsign-conversion, the patch as it looks reasonable (and in the first hunk, improves readability as well). BB all green, here we go :-)

Your patch has been applied to the master branch.

commit 0401eacfe255ccd7b41fa594e004fddeb8ba1a24

Author: Frank Lichtenheld
Date:   Fri Mar 6 17:33:31 2026 +0100
     Fix various sign-compare warnings due to write return value

     Signed-off-by: Frank Lichtenheld <[email protected]...>
     Acked-by: Gert Doering <[email protected]...>
     Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1513
     Message-Id: <[email protected]...>
     URL: https://www.mail-archive.com/[email protected]/msg35963.html
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering

#5 lore raw
In reply to a message not in the archive

cron2 has uploaded a new patch set (#4) to the change originally created by flichtenheld. ( http://gerrit.openvpn.net/c/openvpn/+/1513?usp=email )

The following approvals got outdated and were removed:
Code-Review+2 by cron2

Change subject: Fix various sign-compare warnings due to write return value
......................................................................

Fix various sign-compare warnings due to write return value

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

Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1513
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg35963.html

---
M src/openvpn/ps.c
M src/openvpn/status.c
M src/plugins/auth-pam/auth-pam.c

3 files changed, 4 insertions(+), 30 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/13/1513/4

src/openvpn/ps.c +2 -10
index c589248..c3f54ed 100644
@@ -327,11 +327,6 @@
     }
 }
 
-#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 @@
         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 @@
     }
 }
 
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic pop
-#endif
-
 /*
  * Cleanup function, on proxy process exit.
  */
src/openvpn/status.c +1 -10
index 4d42863..c7d375b 100644
@@ -206,11 +206,6 @@
     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 @@
         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 @@
     }
 }
 
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic pop
-#endif
-
 bool
 status_read(struct status_output *so, struct buffer *buf)
 {
src/plugins/auth-pam/auth-pam.c +1 -10
index 0f3346f..3b7bcc2 100644
@@ -184,15 +184,10 @@
     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 @@
     }
 }
 
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic pop
-#endif
-
 #ifdef DO_DAEMONIZE
 
 /*

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1513?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: newpatchset
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I3eb4581980f532cb2960b37a6fa43a7baee4b603
Gerrit-Change-Number: 1513
Gerrit-PatchSet: 4
Gerrit-Owner: flichtenheld <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>

#6 lore raw
In reply to a message not in the archive

cron2 has submitted this change. ( http://gerrit.openvpn.net/c/openvpn/+/1513?usp=email )

Change subject: Fix various sign-compare warnings due to write return value
......................................................................

Fix various sign-compare warnings due to write return value

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

Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1513
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg35963.html

---
M src/openvpn/ps.c
M src/openvpn/status.c
M src/plugins/auth-pam/auth-pam.c

3 files changed, 4 insertions(+), 30 deletions(-)
src/openvpn/ps.c +2 -10
index c589248..c3f54ed 100644
@@ -327,11 +327,6 @@
     }
 }
 
-#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 @@
         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 @@
     }
 }
 
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic pop
-#endif
-
 /*
  * Cleanup function, on proxy process exit.
  */
src/openvpn/status.c +1 -10
index 4d42863..c7d375b 100644
@@ -206,11 +206,6 @@
     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 @@
         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 @@
     }
 }
 
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic pop
-#endif
-
 bool
 status_read(struct status_output *so, struct buffer *buf)
 {
src/plugins/auth-pam/auth-pam.c +1 -10
index 0f3346f..3b7bcc2 100644
@@ -184,15 +184,10 @@
     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 @@
     }
 }
 
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic pop
-#endif
-
 #ifdef DO_DAEMONIZE
 
 /*

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1513?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: merged
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I3eb4581980f532cb2960b37a6fa43a7baee4b603
Gerrit-Change-Number: 1513
Gerrit-PatchSet: 4
Gerrit-Owner: flichtenheld <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>