From: "flichtenheld (Code Review)"
Date: Wed, 24 Sep 2025 13:17:55 +0000
In-Reply-To:
References:
Reply-To: frank@...2641..., arne-openvpn@...1227...,
openvpn-devel@lists.sourceforge.net
Message-ID: <4587e485c86eabb688c4dd213e45512d5f51a9bf-EmailReplacePatchSet-HTML@...2715...>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Content-Disposition: inline
Content-Type: multipart/alternative; boundary="bB8GddNcqy4="; 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
--bB8GddNcqy4=
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 reexamine a change. Please visit
http://gerrit.openvpn.net/c/openvpn/+/1207?usp=3Demail
to look at the new patch set (#3).
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/3
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 3f6196f..d53369b 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -114,7 +114,7 @@
check_and_add_compiler_flag(-Wstrict-prototypes StrictPrototypes)
check_and_add_compiler_flag(-Wold-style-definition OldStyleDefinition)
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 8f3c01d..44c7b65 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1399,7 +1399,7 @@
ACL_CHECK_ADD_COMPILE_FLAGS([-Wold-style-definition])
ACL_CHECK_ADD_COMPILE_FLAGS([-Wconversion -Wno-sign-conversion])
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 2f60b78..9c8248a 100644
--- a/src/openvpn/event.c
+++ b/src/openvpn/event.c
@@ -409,6 +409,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
*/
@@ -473,6 +480,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 f8a0fee..1ce855c2 100644
--- a/src/openvpn/init.c
+++ b/src/openvpn/init.c
@@ -2729,7 +2729,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 f71d891..23b6439 100644
--- a/src/openvpn/socket.c
+++ b/src/openvpn/socket.c
@@ -577,7 +577,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=3D SOCKET_UNDEFINED)
{
msg(M_ERR, "Cannot create TCP socket");
}
@@ -608,7 +609,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=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: 3
Gerrit-Owner: flichtenheld
Gerrit-Reviewer: plaisthos
Gerrit-CC: openvpn-devel
Gerrit-Attention: plaisthos
Gerrit-MessageType: newpatchset
--bB8GddNcqy4=
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Attention is currently required from: plaisthos.
flichtenheld uploaded patch set #3 to this change.
<=
p>View C=
hange
Enable -Wtype-limits by default (via -Wextra) Removes a fe=
w smaller instances: - Fix return type check for socket() on Windows/Un=
ixy - 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 <frank@...2641...> --- M CMakeLists.txt M =
configure.ac M src/openvpn/event.c M src/openvpn/init.c M src/open=
vpn/socket.c 5 files changed, 17 insertions(+), 5 deletions(-) =
pre>git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/07/1207/3<=
span>diff --git a/CMakeLists.txt b/CMakeLists.txtindex 3f6=
196f..d53369b 100644 --- a/CMakeLists.txt +=
++ b/CMakeLists.txt @@ -114,7 +114,7 @@ =
check_and_add_compiler_flag(-Wstrict-prototypes StrictPrototypes) <=
br> check_and_add_compiler_flag(-Wold-style-definition OldStyleDe=
finition) add_compile_options(-Wconversion -Wno-sign-c=
onversion) - add_com=
pile_options(-Wextra -Wno-sign-compare -Wno-type-limits -Wno-unused-paramet=
er) + add_compile_=
options(-Wextra -Wno-sign-compare -Wno-unused-parameter) =
# clang doesn't have the different levels but also doesn't inclu=
de it in -Wextra check_and_add_compiler_flag(-Wimplici=
t-fallthrough=3D2 GCCImplicitFallthrough) if (WIN32)=
span>diff --git a/configure.ac b/configure.ac ind=
ex 8f3c01d..44c7b65 100644 --- a/configure.ac +++ b/configure.ac @@ -1399,7 +1399,7 @@ ACL_CHECK_ADD_COMPILE_FLAGS([-Wold-style-definition]) AC=
L_CHECK_ADD_COMPILE_FLAGS([-Wconversion -Wno-sign-conversion]) ACL_CHECK_ADD_COMPILE_FLAGS([-Wall])-ACL_CHECK_ADD_COMPILE_FLAGS([-Wextra -Wno-sign-compare =
-Wno-type-limits -Wno-unused-parameter]) +ACL_CHECK_ADD_COMPILE_FLAGS([-Wextra -Wno-sign-compare=
-Wno-unused-parameter]) # clang doesn't have the diff=
erent levels but also doesn't include it in -Wextra AC=
L_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 2f60=
b78..9c8248a 100644 --- a/src/openvpn/event.c +++ b/src/openvpn/event.c@@ -409,6 +409,13 @@ } #endif + /* WSA_WAIT_EVENT_0 =3D=3D 0 but th=
e API documentation is written in a way + that doesn't guarantee that. So we make usel=
ess checks. */ +#if d=
efined(__GNUC__) +#pr=
agma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wtype-limits" +#endif+ /* =
* First poll our event list with 0 timeout */ =
@@ -473,6 +480,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 f8a0fee..1ce8=
55c2 100644 --- a/src/openvpn/init.c +++ b/=
src/openvpn/init.c @@ -2729,7 +2729,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_DATA_KEY_FORMAT); - bool datav2_enabled =
=3D (c->options.peer_id >=3D 0 && c->options.peer_id < =
MAX_PEER_ID); + bo=
ol datav2_enabled =3D c->options.peer_id < MAX_PEER_ID; if (epoch_data && !datav2_enabled) =
{ diff --git a/src/openvpn/socket.c b/src/op=
envpn/socket.c index f71d891..23b6439 100644 --- a/src/openvpn/socket.c+++ b/src/openvpn/socket.c @@ -577,7 +577,8 @@ ASSERT(addrinfo); ASSERT(addrinfo->ai_socktype =3D=3D SOCK_STREAM); - if (=
(sd =3D socket(addrinfo->ai_family, addrinfo->ai_socktype, addrinfo-&=
gt;ai_protocol)) < 0) + if ((sd =3D socket(addrinfo->ai_family, addrinfo->ai_socktyp=
e, addrinfo->ai_protocol)) + =3D=3D SOCKET_UNDEFINED) { msg(M_ERR, "Cannot create TCP socket"); } @@ -608,7 +609,8 @@ ASSE=
RT(addrinfo); ASSERT(addrinfo->ai_socktype =3D=3D S=
OCK_DGRAM); - if ((sd =3D socket(addrinfo->ai_family, addrinfo->ai_sock=
type, addrinfo->ai_protocol)) < 0) + if ((sd =3D socket(addrinfo->ai_family, addrinf=
o->ai_socktype, addrinfo->ai_protocol)) + =3D=3D SOCKET_UNDEFINED) =
{ msg(M_ERR, "UDP: Cannot create UDP/UDP=
6 socket"); } To view, visit change 1207 . To unsubscribe, or for help writing mail filters=
, visit settings .
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Iaabddb6f81cd94863291b193aae=
9d384a8f9d871
Gerrit-Change-Number: 1207
Gerrit-PatchSet: 3
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: newpatchset
--bB8GddNcqy4=--