From: "flichtenheld (Code Review)" Date: Tue, 23 Sep 2025 11:34:05 +0000 References: Reply-To: frank@...2641..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net Message-ID: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="84ILb06qx58="; charset=UTF-8 Subject: [Openvpn-devel] [S] Change in openvpn[master]: Enable -Wtype-limits by default (via -Wextra) List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: plaisthos Cc: openvpn-devel --84ILb06qx58= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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/+/1207?usp=3Demail to review the following change. Change subject: Enable -Wtype-limits by default (via -Wextra) ...................................................................... Enable -Wtype-limits by default (via -Wextra) Removes a few smaller instances: - Fix return type check for socket() on Windows/Unixy - Ignore a few instances related to WSAWaitForMultipleEvents. The compiler says the check is currently useless, but we follow the API documentation. - Fix one check that assumed peer_id was signed. Change-Id: Iaabddb6f81cd94863291b193aae9d384a8f9d871 Signed-off-by: Frank Lichtenheld --- M CMakeLists.txt M configure.ac M src/openvpn/event.c M src/openvpn/init.c M src/openvpn/socket.c 5 files changed, 17 insertions(+), 5 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/07/1207/1 diff --git a/CMakeLists.txt b/CMakeLists.txt index fdc0162..e4e0b51 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -115,7 +115,7 @@ check_and_add_compiler_flag(-Wold-style-definition OldStyleDefinition) # We are not ready for this #add_compile_options(-Wconversion -Wno-sign-conversion) - add_compile_options(-Wextra -Wno-sign-compare -Wno-type-limits -Wno-un= used-parameter) + add_compile_options(-Wextra -Wno-sign-compare -Wno-unused-parameter) # clang doesn't have the different levels but also doesn't include it = in -Wextra check_and_add_compiler_flag(-Wimplicit-fallthrough=3D2 GCCImplicitFall= through) if (WIN32) diff --git a/configure.ac b/configure.ac index c2feeea..8fc27c3 100644 --- a/configure.ac +++ b/configure.ac @@ -1398,7 +1398,7 @@ ACL_CHECK_ADD_COMPILE_FLAGS([-Wstrict-prototypes]) ACL_CHECK_ADD_COMPILE_FLAGS([-Wold-style-definition]) ACL_CHECK_ADD_COMPILE_FLAGS([-Wall]) -ACL_CHECK_ADD_COMPILE_FLAGS([-Wextra -Wno-sign-compare -Wno-type-limits -W= no-unused-parameter]) +ACL_CHECK_ADD_COMPILE_FLAGS([-Wextra -Wno-sign-compare -Wno-unused-paramet= er]) # clang doesn't have the different levels but also doesn't include it in -= Wextra ACL_CHECK_ADD_COMPILE_FLAGS([-Wimplicit-fallthrough=3D2]) if test "${WIN32}" =3D "yes"; then diff --git a/src/openvpn/event.c b/src/openvpn/event.c index 581bdbb..77f859f 100644 --- a/src/openvpn/event.c +++ b/src/openvpn/event.c @@ -400,6 +400,13 @@ } #endif + /* WSA_WAIT_EVENT_0 =3D=3D 0 but the API documentation is written in a= way + that doesn't guarantee that. So we make useless checks. */ +#if defined(__GNUC__) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wtype-limits" +#endif + /* * First poll our event list with 0 timeout */ @@ -464,6 +471,9 @@ return -1; } } +#if defined(__GNUC__) +#pragma GCC diagnostic pop +#endif } static struct event_set * diff --git a/src/openvpn/init.c b/src/openvpn/init.c index 0d7a2ec..62b8138 100644 --- a/src/openvpn/init.c +++ b/src/openvpn/init.c @@ -2724,7 +2724,7 @@ /* Ensure that for epoch data format is only enabled if also data v2 * is enabled */ bool epoch_data =3D (c->options.imported_protocol_flags & CO_EPOCH_DAT= A_KEY_FORMAT); - bool datav2_enabled =3D (c->options.peer_id >=3D 0 && c->options.peer_= id < MAX_PEER_ID); + bool datav2_enabled =3D c->options.peer_id < MAX_PEER_ID; if (epoch_data && !datav2_enabled) { diff --git a/src/openvpn/socket.c b/src/openvpn/socket.c index 94f16c7..9839357 100644 --- a/src/openvpn/socket.c +++ b/src/openvpn/socket.c @@ -572,7 +572,8 @@ ASSERT(addrinfo); ASSERT(addrinfo->ai_socktype =3D=3D SOCK_STREAM); - if ((sd =3D socket(addrinfo->ai_family, addrinfo->ai_socktype, addrinf= o->ai_protocol)) < 0) + if ((sd =3D socket(addrinfo->ai_family, addrinfo->ai_socktype, addrinf= o->ai_protocol)) + !=3D SOCKET_UNDEFINED) { msg(M_ERR, "Cannot create TCP socket"); } @@ -603,7 +604,8 @@ ASSERT(addrinfo); ASSERT(addrinfo->ai_socktype =3D=3D SOCK_DGRAM); - if ((sd =3D socket(addrinfo->ai_family, addrinfo->ai_socktype, addrinf= o->ai_protocol)) < 0) + if ((sd =3D socket(addrinfo->ai_family, addrinfo->ai_socktype, addrinf= o->ai_protocol)) + !=3D SOCKET_UNDEFINED) { msg(M_ERR, "UDP: Cannot create UDP/UDP6 socket"); } -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/1207?usp=3Demail To unsubscribe, or for help writing mail filters, visit http://gerrit.openv= pn.net/settings Gerrit-Project: openvpn Gerrit-Branch: master Gerrit-Change-Id: Iaabddb6f81cd94863291b193aae9d384a8f9d871 Gerrit-Change-Number: 1207 Gerrit-PatchSet: 1 Gerrit-Owner: flichtenheld Gerrit-Reviewer: plaisthos Gerrit-CC: openvpn-devel Gerrit-Attention: plaisthos Gerrit-MessageType: newchange --84ILb06qx58= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Attention is currently required from: plaisthos.

flichtenheld would like plaisthos to review this change.

V= iew Change

Enable -Wtype-limits by default (via -Wextra)

Removes= a few smaller instances:
- Fix return type check for socket() on Windo= ws/Unixy
- Ignore a few instances related to WSAWaitForMultipleEvents.<= br> The compiler says the check is currently useless, but
we follow= the API documentation.
- Fix one check that assumed peer_id was signed= .

Change-Id: Iaabddb6f81cd94863291b193aae9d384a8f9d871
Signed-off= -by: Frank Lichtenheld <frank@...2641...>
---
M CMakeLists.txt<= br>M configure.ac
M src/openvpn/event.c
M src/openvpn/init.c
M src= /openvpn/socket.c
5 files changed, 17 insertions(+), 5 deletions(-)
<= br>
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/07/1207/=
1
diff --git a/CMakeLists.txt b/CMakeLists.txt
inde= x fdc0162..e4e0b51 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -115,7 +115,7 @@
check_and_add_compiler_flag(-Wold-style-definition OldStyleDefinitio= n)
# We are not ready for this
#a= dd_compile_options(-Wconversion -Wno-sign-conversion)
- add_compile_options(-Wextra -Wno-sign-c= ompare -Wno-type-limits -Wno-unused-parameter)
+ add_compile_options(-Wextra -Wno-sign-compar= e -Wno-unused-parameter)
# clang doesn't have the = different levels but also doesn't include it in -Wextra
check_and_add_compiler_flag(-Wimplicit-fallthrough=3D2 GCCImplicitFal= lthrough)
if (WIN32)
diff --git a/conf= igure.ac b/configure.ac
index c2feeea..8fc27c3 100644

--- a/configure.ac
+++ b/configure.ac
= @@ -1398,7 +1398,7 @@
ACL_CHECK_ADD_COMPILE_FLAGS([-= Wstrict-prototypes])
ACL_CHECK_ADD_COMPILE_FLAGS([-Wold-st= yle-definition])
ACL_CHECK_ADD_COMPILE_FLAGS([-Wall])

-ACL_CHECK_ADD_COMPILE_FLAG= S([-Wextra -Wno-sign-compare -Wno-type-limits -Wno-unused-parameter])
+ACL_CHECK_ADD_COMPILE_FLA= GS([-Wextra -Wno-sign-compare -Wno-unused-parameter])
# cl= ang doesn't have the different levels but also doesn't include it i= n -Wextra
ACL_CHECK_ADD_COMPILE_FLAGS([-Wimplicit-fallthro= ugh=3D2])
if test "${WIN32}" =3D "yes"= ; then
diff --git a/src/openvpn/event.c b/src/openvpn/event= .c
index 581bdbb..77f859f 100644
--- a/src/= openvpn/event.c
+++ b/src/openvpn/event.c
@= @ -400,6 +400,13 @@
}
#endif
+ /* WSA= _WAIT_EVENT_0 =3D=3D 0 but the API documentation is written in a way=
+ that doesn't gu= arantee that. So we make useless checks. */
+#if defined(__GNUC__)
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wty= pe-limits"
+#end= if
+
= /*
* First poll our event list with 0 timeout

*/
@@ -464,6 +471,9 @@
= return -1;
}
}
+#if defined(__GNUC__)=
+#pragma GCC diagnos= tic pop
+#endif
}

static struct event_set *<= /span>
diff --git a/src/openvpn/init.c b/src/openvpn/init.c=
index 0d7a2ec..62b8138 100644
--- a/src/openvpn/i= nit.c
+++ b/src/openvpn/init.c
@@ -2724,7 += 2724,7 @@
/* Ensure that for epoch data format is only= enabled if also data v2
* is enabled */
bool epoch_data =3D (c->options.imported_protocol_flags & C= O_EPOCH_DATA_KEY_FORMAT);

- bool datav2_enabled =3D (c->options.peer_id >=3D 0 &&= c->options.peer_id < MAX_PEER_ID);
+ bool datav2_enabled =3D c->options.peer_id <= ; MAX_PEER_ID;

if (epoch_data &&= amp; !datav2_enabled)
{
diff --git a/s= rc/openvpn/socket.c b/src/openvpn/socket.c
index 94f16c7..9= 839357 100644
--- a/src/openvpn/socket.c
++= + b/src/openvpn/socket.c
@@ -572,7 +572,8 @@
ASSERT(addrinfo);

ASSERT(addrinfo->ai_sockty= pe =3D=3D SOCK_STREAM);

- if ((sd =3D socket(addrinfo->ai_family, addrinfo= ->ai_socktype, addrinfo->ai_protocol)) < 0)
+ if ((sd =3D socket(addrinfo->ai_fa= mily, addrinfo->ai_socktype, addrinfo->ai_protocol))
+ !=3D SOCKET_UNDEFINED)
{
msg(M_ERR, "Cannot create T= CP socket");
}
@@ -603,7 +604,8 @= @
ASSERT(addrinfo);
ASSERT(addrin= fo->ai_socktype =3D=3D SOCK_DGRAM);

- if ((sd =3D socket(addrinfo->ai_f= amily, addrinfo->ai_socktype, addrinfo->ai_protocol)) < 0)<= br>+ if ((sd =3D socket(addr= info->ai_family, addrinfo->ai_socktype, addrinfo->ai_protocol))
+ !=3D SOCKET_UN= DEFINED)
{
msg(M_ERR, "U= DP: Cannot create UDP/UDP6 socket");
}
=

To view, visit change 1207. To unsubscribe, or for he= lp writing mail filters, visit settings.

<= /div>
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Iaabddb6f81cd94863291b193aae= 9d384a8f9d871
Gerrit-Change-Number: 1207
Gerrit-PatchSet: 1
Gerrit-Owner: flichtenheld <frank@...2723...= .>
Gerrit-Reviewer: plaisthos <arne-openvpn@...1186...= .1227...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
Gerrit-Attention: plaisthos <arne-openvpn@...220...= ..1227...>
Gerrit-MessageType: newchange
--84ILb06qx58=--