What happened
get_source_plugin_stats_v2 in the source_plugin engine has a NULL check on
stats that can never be true.
userspace/libscap/engine/source_plugin/source_plugin.c (master), around
line 290:
metrics_v2* stats = handle->m_stats;
if(!stats) { // always false
*nstats = 0;
*rc = SCAP_FAILURE;
return NULL;
}
m_stats is an array member of the engine struct, not a pointer -
userspace/libscap/engine/source_plugin/source_plugin.h:
metrics_v2 m_stats[MAX_SOURCE_PLUGIN_COUNTERS_STATS];
So stats = handle->m_stats always decays to the address of the first element,
which is non-null whenever handle is valid (and handle is already
dereferenced two lines above without a check). The if(!stats) branch is dead
code.
Flagged by static analysis as a redundant comparison that is always false at
source_plugin.c:291, and confirmed by reading the code.
Why it matters
No functional impact - the branch never runs, so behaviour is unchanged. It's
dead code that trips static analyzers and is slightly misleading (it reads like
a real allocation-failure guard, but m_stats is never allocated or nullable).
Suggested change
Drop the check:
metrics_v2* stats = handle->m_stats;
/* SOURCE PLUGIN STATS COUNTERS */
for(uint32_t stat = 0; stat < MAX_SOURCE_PLUGIN_COUNTERS_STATS; stat++) {
...
}
Note
The same metrics_v2* stats = <array member>; if(!stats) pattern likely exists
in other engines' get_stats_v2 implementations, so this could be swept in one
cleanup if wanted.
What happened
get_source_plugin_stats_v2in the source_plugin engine has a NULL check onstatsthat can never be true.userspace/libscap/engine/source_plugin/source_plugin.c(master), aroundline 290:
m_statsis an array member of the engine struct, not a pointer -userspace/libscap/engine/source_plugin/source_plugin.h:So
stats = handle->m_statsalways decays to the address of the first element,which is non-null whenever
handleis valid (andhandleis alreadydereferenced two lines above without a check). The
if(!stats)branch is deadcode.
Flagged by static analysis as a redundant comparison that is always false at
source_plugin.c:291, and confirmed by reading the code.Why it matters
No functional impact - the branch never runs, so behaviour is unchanged. It's
dead code that trips static analyzers and is slightly misleading (it reads like
a real allocation-failure guard, but
m_statsis never allocated or nullable).Suggested change
Drop the check:
Note
The same
metrics_v2* stats = <array member>; if(!stats)pattern likely existsin other engines'
get_stats_v2implementations, so this could be swept in onecleanup if wanted.