[Openvpn-devel,v1] cppcheck: Fix handling of likely() on Windows

Message ID 20260928141559.11880-1-gert@greenie.muc.de
State New
Headers
Series [Openvpn-devel,v1] cppcheck: Fix handling of likely() on Windows |

Commit Message

Gert Doering Sept. 28, 2026, 2:15 p.m. UTC
  From: Frank Lichtenheld <frank@lichtenheld.com>

Since we do not force __GNUC__ to undefined on Windows
(since we want to support MinGW) cppcheck might stumble
upon __builtin_expect(). When running with gnu.cfg (which
we do not want to do for Windows code) then that has an
existing override. But for our Windows checks we need to
add our own override.

This caused false-positives in buffer code.

Change-Id: I3b835558451414d8a4e8058114643555be69d391
Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com>
Acked-by: Arne Schwabe <arne-openvpn@rfc2549.org>
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1957
---

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/+/1957
This mail reflects revision 1 of this Change.

Acked-by according to Gerrit (reflected above):
Arne Schwabe <arne-openvpn@rfc2549.org>
  

Comments

Gert Doering Sept. 28, 2026, 9:11 p.m. UTC | #1
Magic things to appease a magic tool... :-)

Your patch has been applied to the master branch.

commit fe1162561c67e036e03bf07276d67d1b05d42cda
Author: Frank Lichtenheld
Date:   Mon Sep 28 16:15:53 2026 +0200

     cppcheck: Fix handling of likely() on Windows

     Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com>
     Acked-by: Arne Schwabe <arne-openvpn@rfc2549.org>
     Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1957
     Message-Id: <20260928141559.11880-1-gert@greenie.muc.de>
     URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg39555.html
     Signed-off-by: Gert Doering <gert@greenie.muc.de>


--
kind regards,

Gert Doering
  

Patch

diff --git a/dev-tools/openvpn-cppcheck-windows.cfg b/dev-tools/openvpn-cppcheck-windows.cfg
new file mode 100644
index 0000000..9ac7282
--- /dev/null
+++ b/dev-tools/openvpn-cppcheck-windows.cfg
@@ -0,0 +1,10 @@ 
+<?xml version ="1.0"?>
+<!-- Only used for the Windows run. Can't be in openvpn-cppcheck-library.cfg
+     because it conflicts with gnu.cfg. -->
+<def>
+  <!-- MinGW uses GCC, so we need to handle GCC builtins. gnu.cfg has these,
+       but we do not load it for Windows. Without this cppcheck does not
+       understand our likely()/unlikely() macros. -->
+  <define name="__builtin_expect(X,Y)" value="(X)" />
+  <define name="__builtin_expect_with_probability(exp,c,probability)" value="(exp)" />
+</def>
diff --git a/dev-tools/run-cppcheck.sh b/dev-tools/run-cppcheck.sh
index 6b2c2be..3c71c83 100755
--- a/dev-tools/run-cppcheck.sh
+++ b/dev-tools/run-cppcheck.sh
@@ -49,7 +49,7 @@ 
     tests/unit_tests/plugins/ || ret=$?
 cppcheck $COMMON_ARGS \
     --platform=win64 \
-    --library=windows.cfg \
+    --library=windows.cfg --library=${SCRIPT_DIR}/openvpn-cppcheck-windows.cfg \
     -D_WIN32 \
     -UTARGET_LINUX -UTARGET_FREEBSD -UTARGET_OPENBSD -UTARGET_NETBSD \
     -UTARGET_DARWIN -UTARGET_ANDROID -UTARGET_SOLARIS -UTARGET_DRAGONFLY \