[Openvpn-devel,v1] Provide minimal netlink defines for cppcheck on FreeBSD and macOS

Message ID 20261103141439.14041-1-gert@greenie.muc.de
State New
Headers
Series [Openvpn-devel,v1] Provide minimal netlink defines for cppcheck on FreeBSD and macOS |

Commit Message

Gert Doering Nov. 3, 2026, 2:14 p.m. UTC
  From: Arne Schwabe <arne@rfc2549.org>

Without these defines and the hidden goto inside the NLA_PUT functions
cppcheck complains about ret in dco_linux.c. This allows to run
cppcheck on macOS and FreeBSD without triggering these warnings.

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

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

Acked-by according to Gerrit (reflected above):
Frank Lichtenheld <frank@lichtenheld.com>
  

Patch

diff --git a/dev-tools/openvpn-cppcheck-netlink.cfg b/dev-tools/openvpn-cppcheck-netlink.cfg
new file mode 100644
index 0000000..b63adf0
--- /dev/null
+++ b/dev-tools/openvpn-cppcheck-netlink.cfg
@@ -0,0 +1,7 @@ 
+<?xml version ="1.0"?>
+<def>
+  <!-- minimal defines to supress the errors on non-Linux platforms that do not have the netlink headers -->
+  <define name="NLA_PUT(msg, attrtype, attrlen, data)" value="if (nla_cppcheck_dummy(msg, attrtype, attrlen, data) < 0) goto nla_put_failure;" />
+  <define name="NLA_PUT_U32(msg, attrtype, value)" value="NLA_PUT(msg, uint32_t, attrtype, value)" />
+  <define name="NLA_PUT_STRING(msg, attrtype, value)" value="NLA_PUT(msg, attrtype, (int) strlen(value) + 1, value)" />
+</def>
diff --git a/dev-tools/run-cppcheck.sh b/dev-tools/run-cppcheck.sh
index d1c22c5..debcd46 100755
--- a/dev-tools/run-cppcheck.sh
+++ b/dev-tools/run-cppcheck.sh
@@ -20,9 +20,11 @@ 
 if [ $(uname) = "Darwin" ] || [ $(uname) = "FreeBSD" ]; then
     SCRIPT_DIR=$(dirname $(readlink -f "${BASH_SOURCE[0]}"))
     num_procs=$(sysctl -n hw.ncpu)
+    EXTRA_LIBRARY="--library=${SCRIPT_DIR}/openvpn-cppcheck-netlink.cfg"
 else
     SCRIPT_DIR=$(dirname $(readlink -e "${BASH_SOURCE[0]}"))
     num_procs=$(nproc)
+    EXTRA_LIBRARY=""
 fi
 : ${SOURCE_DIR:=$SCRIPT_DIR/..}
 : ${BUILD_DIR:=$PWD}
@@ -35,6 +37,7 @@ 
  -I${BUILD_DIR} -I${BUILD_DIR}/include/ \
  --enable=all ${disable_arg} \
  --library=${SCRIPT_DIR}/openvpn-cppcheck-library.cfg \
+ ${EXTRA_LIBRARY} \
  --library=openssl.cfg \
  --suppress-xml=${SCRIPT_DIR}/cppcheck-suppressions.xml --inline-suppr \
  --cppcheck-build-dir=${CPPCHECK_DIR} \