]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
SNMP: Remove extraneous va_start() from snmpAddNode() (#2228)
authorJoshua Rogers <MegaManSec@users.noreply.github.com>
Tue, 21 Oct 2025 14:52:18 +0000 (14:52 +0000)
committerSquid Anubis <squid-anubis@squid-cache.org>
Tue, 21 Oct 2025 21:35:49 +0000 (21:35 +0000)
Also polished snmpAddNode() implementation, including adding
`mib_tree_head->parent` initialization.

src/snmp_core.cc

index 0af67f3d15882ed6ab3501feb3c2847b90995659..ffd93c2063614d7eb68c4fee49a757e73b170972 100644 (file)
@@ -990,34 +990,31 @@ snmpAddNodeStr(const char *base_str, int o, oid_ParseFn * parsefunction, instanc
 static mib_tree_entry *
 snmpAddNode(oid * name, int len, oid_ParseFn * parsefunction, instance_Fn * instancefunction, AggrType aggrType, int children,...)
 {
-    va_list args;
-    int loop;
-    mib_tree_entry *entry = nullptr;
-    va_start(args, children);
-
     MemBuf tmp;
     debugs(49, 6, "snmpAddNode: Children : " << children << ", Oid : " << snmpDebugOid(name, len, tmp));
 
-    va_start(args, children);
-    entry = (mib_tree_entry *)xmalloc(sizeof(mib_tree_entry));
+    const auto entry = static_cast<mib_tree_entry *>(xmalloc(sizeof(mib_tree_entry)));
     entry->name = name;
     entry->len = len;
     entry->parsefunction = parsefunction;
     entry->instancefunction = instancefunction;
     entry->children = children;
     entry->leaves = nullptr;
+    entry->parent = nullptr;
     entry->aggrType = aggrType;
 
     if (children > 0) {
-        entry->leaves = (mib_tree_entry **)xmalloc(sizeof(mib_tree_entry *) * children);
+        entry->leaves = static_cast<mib_tree_entry **>(xmalloc(sizeof(mib_tree_entry *) * children));
 
-        for (loop = 0; loop < children; ++loop) {
+        va_list args;
+        va_start(args, children);
+        for (int loop = 0; loop < children; ++loop) {
             entry->leaves[loop] = va_arg(args, mib_tree_entry *);
             entry->leaves[loop]->parent = entry;
         }
+        va_end(args);
     }
 
-    va_end(args);
     return (entry);
 }
 /* End of tree utility functions */