A bunch more cppcheck cleanup

This commit is contained in:
Cary R 2026-01-13 01:20:10 -08:00
parent 6651df6f2c
commit 951ede0922
33 changed files with 711 additions and 603 deletions

View File

@ -145,6 +145,7 @@ bool PECastSize::has_aa_term(Design *des, NetScope *scope) const
PECastType::PECastType(data_type_t*t, PExpr*b)
: target_(t), base_(b)
{
target_type_ = nullptr;
}
PECastType::~PECastType()

View File

@ -1,7 +1,7 @@
#ifndef IVL_PGate_H
#define IVL_PGate_H
/*
* Copyright (c) 1998-2025 Stephen Williams (steve@icarus.com)
* Copyright (c) 1998-2026 Stephen Williams (steve@icarus.com)
*
* This source code is free software; you can redistribute it
* and/or modify it in source code form under the terms of the GNU
@ -215,8 +215,6 @@ class PGModule : public PGate {
void set_parameters(std::list<PExpr*>*o);
void set_parameters(named_pexpr_t *pa, unsigned npa);
std::map<perm_string,PExpr*> attributes;
virtual void dump(std::ostream&out, unsigned ind =4) const override;
virtual void elaborate(Design*, NetScope*scope) const override;
virtual void elaborate_scope(Design*des, NetScope*sc) const override;

View File

@ -11,6 +11,22 @@ constVariablePointer:main.cc:400
constVariablePointer:main.cc:404
constVariablePointer:main.cc:654
// const auto should be const
constVariablePointer:elab_expr.cc:344
constVariablePointer:elab_expr.cc:413
// The reference cannot be const since it is updated in the calling function.
constParameterReference:net_udp.cc:37
// These cannot be static since they access object data
functionStatic:net_link.cc:178
functionStatic:net_link.cc:183
functionStatic:net_link.cc:188
functionStatic:net_link.cc:193
// This cannot be static when checking with valgrind
functionStatic:libmisc/StringHeap.cc
// Skip not initialized in the constructor for target scope
uninitMemberVar:t-dll.cc
@ -31,6 +47,26 @@ duplicateCondition:elaborate.cc:7672
// To complicated to use std::find_if()
useStlAlgorithm:map_named_args.cc:38
// The condition is always true at least once based on the previous assertion
derefInvalidIterator:netmisc.cc:420
// We only use a StringHeap or a StringHepLex
duplInheritedMember:libmisc/StringHeap.h:99
duplInheritedMember:libmisc/StringHeap.h:100
duplInheritedMember:libmisc/StringHeap.cc:160
duplInheritedMember:libmisc/StringHeap.cc:182
// cppcheck is wrong this is correct usage
redundantAssignment:syn-rules.y:230
redundantAssignment:syn-rules.y:234
redundantAssignment:syn-rules.y:243
redundantAssignment:syn-rules.y:271
redundantAssignment:syn-rules.y:274
redundantAssignment:syn-rules.y:294
// Cannot define a constructor sine this is in the parser union
noConstructor:property_qual.h:22
// This are just stubs
// vpi_control()
unusedFunction:vpi_modules.cc:109
@ -688,13 +724,13 @@ unusedFunction:netlist.cc:111
// find_link()
unusedFunction:netlist.cc:297
// set_module_port_index()
unusedFunction:netlist.cc:649
unusedFunction:netlist.cc:651
// width_a()
unusedFunction:netlist.cc:1674
unusedFunction:netlist.cc:1678
// width_b()
unusedFunction:netlist.cc:1679
unusedFunction:netlist.cc:1683
// result_sig()
unusedFunction:netlist.cc:2180
unusedFunction:netlist.cc:2184
// test_protected()
unusedFunction:property_qual.h:50
// test_rand()
@ -708,7 +744,7 @@ unusedFunction:t-dll-expr.cc:91
// net_assign()
unusedFunction:t-dll.cc:2368
// is_before()
unusedFunction:verinum.cc:589
unusedFunction:verinum.cc:588
// Errors/limitations in the generated yacc and lex files
constVariablePointer:<stdout>

View File

@ -69,11 +69,12 @@ distclean: clean
cppcheck: $(O:.o=.c)
cppcheck --enable=all --std=c99 --std=c++11 -f \
-UYY_USER_INIT \
-UYYPARSE_PARAM -UYYPRINT -Ushort -Uyyoverflow \
-UYYTYPE_INT8 -UYYTYPE_INT16 -UYYTYPE_UINT8 -UYYTYPE_UINT16 \
-UYYSTYPE -U__SIZE_TYPE__ -Umalloc -Usize_t -Ufree \
$(INCLUDE_PATH) $^
--check-level=exhaustive \
--suppressions-list=$(srcdir)/../cppcheck-global.sup \
--suppressions-list=$(srcdir)/cppcheck.sup \
-Ushort -Usize_t -Uyyoverflow \
-U__SIZE_TYPE__ -Umalloc -Ufree \
--relative-paths=$(srcdir) $(INCLUDE_PATH) $^
Makefile: $(srcdir)/Makefile.in ../config.status
cd ..; ./config.status --file=driver/$@

31
driver/cppcheck.sup Normal file
View File

@ -0,0 +1,31 @@
// cppcheck is wrong this is correct usage
syntaxError:main.c:405
syntaxError:main.c:408
// cppcheck is missing the code adds a \0 at the previous location.
knownConditionTrueFalse:main.c:1086
redundantAssignment:main.c:1085
// Skip all memory issues since they should be handled by ivl_alloc.h
memleakOnRealloc
nullPointerArithmeticOutOfMemory
nullPointerOutOfMemory
// Errors/limitations in the generated yacc and lex files
duplicateBreak:cflexor.lex
constVariablePointer:cfparse.y
memleakOnRealloc:cfparse.y
allocaCalled:cfparse.c
constParameterPointer:cfparse.c
constVariablePointer:cfparse.c
invalidPrintfArgType_sint:cfparse.c
knownConditionTrueFalse:cfparse.c
sizeofwithnumericparameter:cfparse.c
syntaxError:cfparse.c
unsignedPositive:cfparse.c
constVariablePointer:<stdout>
nullPointer:<stdout>
redundantInitialization:<stdout>
staticFunction:<stdout>
syntaxError:<stdout>
unusedFunction:<stdout>

View File

@ -1,5 +1,5 @@
const char COPYRIGHT[] =
"Copyright (c) 2000-2025 Stephen Williams (steve@icarus.com)";
"Copyright (c) 2000-2026 Stephen Williams (steve@icarus.com)";
/*
* This source code is free software; you can redistribute it
* and/or modify it in source code form under the terms of the GNU
@ -887,7 +887,8 @@ static void add_env_vpi_module_path(const char*path)
static void get_env_vpi_module_paths(void)
{
char *var = getenv("IVERILOG_VPI_MODULE_PATH");
char *ptr, *end;
char *ptr;
const char *end;
if (!var)
return;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2002-2010 Stephen Williams (steve@icarus.com)
* Copyright (c) 2002-2026 Stephen Williams (steve@icarus.com)
*
* This source code is free software; you can redistribute it
* and/or modify it in source code form under the terms of the GNU
@ -37,7 +37,7 @@ char* substitutions(const char*str)
it in the destination with the contents of the
environment variable x. */
char*name;
char*value;
const char*value;
const char*ep = strchr(str, (str[1]=='(') ? ')' : '}');
str += 2;

View File

@ -63,7 +63,8 @@ cppcheck: $(O:.o=.c)
cppcheck --enable=all --std=c99 --std=c++11 -f \
--check-level=exhaustive \
--suppressions-list=$(srcdir)/../cppcheck-global.sup \
$(INCLUDE_PATH) $^
--suppressions-list=$(srcdir)/cppcheck.sup \
--relative-paths=$(srcdir) $(INCLUDE_PATH) $^
Makefile: $(srcdir)/Makefile.in ../config.status
cd ..; ./config.status --file=ivlpp/$@

16
ivlpp/cppcheck.sup Normal file
View File

@ -0,0 +1,16 @@
// Skip the sscanf() field width limit warning
invalidscanf:lexor.lex:1495
// Skip all memory issues since they should be handled by ivl_alloc.h
memleakOnRealloc
nullPointerArithmeticOutOfMemory
nullPointerOutOfMemory
// Errors/limitations in the generated yacc and lex files
ctunullpointerOutOfMemory:lexor.lex
memleakOnRealloc:lexor.lex
nullPointerOutOfMemory:lexor.lex
constVariablePointer:<stdout>
nullPointer:<stdout>
staticFunction:<stdout>
unusedFunction:<stdout>

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,5 @@
const char COPYRIGHT[] =
"Copyright (c) 1999-2025 Stephen Williams (steve@icarus.com)";
"Copyright (c) 1999-2026 Stephen Williams (steve@icarus.com)";
/*
* This source code is free software; you can redistribute it
* and/or modify it in source code form under the terms of the GNU
@ -245,9 +245,9 @@ int main(int argc, char*argv[])
unsigned lp;
const char*flist_path = 0;
unsigned flag_errors = 0;
char*out_path = 0;
const char*out_path = 0;
FILE*out;
char*precomp_out_path = 0;
const char*precomp_out_path = 0;
FILE*precomp_out = NULL;
/* Define preprocessor keywords that I plan to just pass. */

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2000-2025 Stephen Williams (steve@icarus.com)
* Copyright (c) 2000-2026 Stephen Williams (steve@icarus.com)
*
* This source code is free software; you can redistribute it
* and/or modify it in source code form under the terms of the GNU
@ -615,8 +615,6 @@ void NetScope::evaluate_parameter_logic_(Design*des, param_ref_t cur)
if (!expr->has_width()) {
expr = pad_to_width(expr, integer_width, *expr);
} else if (param_type->slice_dimensions().size()==0 && !expr->has_width()) {
expr = pad_to_width(expr, integer_width, *expr);
}
break;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2000-2025 Stephen Williams (steve@icarus.com)
* Copyright (c) 2000-2026 Stephen Williams (steve@icarus.com)
*
* This source code is free software; you can redistribute it
* and/or modify it in source code form under the terms of the GNU
@ -30,6 +30,7 @@ using namespace std;
NetEvent::NetEvent(perm_string n)
: name_(n)
{
lexical_pos_ = 0;
local_flag_ = false;
scope_ = 0;
snext_ = 0;

View File

@ -319,6 +319,8 @@ NetDelaySrc::NetDelaySrc(NetScope*s, perm_string n, unsigned npins,
for (unsigned idx = 0 ; idx < npins ; idx += 1) {
pin(idx).set_dir(Link::INPUT);
}
for (unsigned dly = 0 ; dly < 12 ; dly += 1)
transition_delays_[dly] = static_cast<uint64_t>(0);
if (condit_src) {
condit_flag_ = true;
@ -996,6 +998,8 @@ NetProcTop::NetProcTop(NetScope*s, ivl_process_type_t t, NetProc*st)
: type_(t), statement_(st), scope_(s)
{
synthesized_design_ = 0;
next_ = nullptr;
}
NetProcTop::~NetProcTop()

View File

@ -813,7 +813,7 @@ class NetNet : public NetObj, public PortType {
unsigned delay_paths(void) const;
const class NetDelaySrc*delay_path(unsigned idx) const;
virtual void dump_net(std::ostream&, unsigned) const;
void dump_net(std::ostream&, unsigned) const;
private:
void initialize_dir_();

View File

@ -373,7 +373,7 @@ struct string_type_t : public data_type_t {
struct class_type_t : public data_type_t {
inline explicit class_type_t(perm_string n) : name(n) { }
inline explicit class_type_t(perm_string n) : name(n) { virtual_class = false; }
void pform_dump(std::ostream&out, unsigned indent) const override;
void pform_dump_init(std::ostream&out, unsigned indent) const;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2002-2025 Stephen Williams (steve@icarus.com)
* Copyright (c) 2002-2026 Stephen Williams (steve@icarus.com)
*
* This source code is free software; you can redistribute it
* and/or modify it in source code form under the terms of the GNU
@ -1639,7 +1639,8 @@ bool NetProcTop::synth_async(Design*des)
connect(nex_set[idx].lnk, latch->pin_Q());
connect(tmp->pin(0), latch->pin_Data());
assert (enables.pin(idx).is_linked());
bool is_linked_tmp = enables.pin(idx).is_linked();
assert (is_linked_tmp);
connect(enables.pin(idx), latch->pin_Enable());
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2000-2025 Stephen Williams (steve@icarus.com)
* Copyright (c) 2000-2026 Stephen Williams (steve@icarus.com)
* Copyright CERN 2013 / Stephen Williams (steve@icarus.com)
*
* This source code is free software; you can redistribute it
@ -2365,7 +2365,7 @@ bool dll_target::replicate(const NetReplicate*net)
* The assignment l-values are captured by the assignment statements
* themselves in the process handling.
*/
void dll_target::net_assign(const NetAssign_*) const
void dll_target::net_assign(const NetAssign_*)
{
}

View File

@ -1,7 +1,7 @@
#ifndef IVL_t_dll_H
#define IVL_t_dll_H
/*
* Copyright (c) 2000-2025 Stephen Williams (steve@icarus.com)
* Copyright (c) 2000-2026 Stephen Williams (steve@icarus.com)
*
* This source code is free software; you can redistribute it
* and/or modify it in source code form under the terms of the GNU
@ -84,7 +84,7 @@ struct dll_target : public target_t, public expr_scan_t {
bool concat(const NetConcat*) override;
bool part_select(const NetPartSelect*) override;
bool replicate(const NetReplicate*) override;
void net_assign(const NetAssign_*) const;
static void net_assign(const NetAssign_*);
bool net_sysfunction(const NetSysFunc*) override;
bool net_function(const NetUserFunc*) override;
bool net_const(const NetConst*) override;

View File

@ -62,6 +62,8 @@ distclean: clean
cppcheck: $(O:.o=.c)
cppcheck --enable=all --std=c99 --std=c++11 -f \
--check-level=exhaustive \
--suppressions-list=$(srcdir)/../cppcheck-global.sup \
--suppressions-list=$(srcdir)/cppcheck.sup \
--relative-paths=$(srcdir) $(INCLUDE_PATH) $^

View File

@ -1,5 +1,6 @@
// These are the global access functions called from the compiler so they
// are not used here.
// Skip strdup() not constant.
constVariablePointer:xilinx.c:323
constVariablePointer:xilinx.c:445
// target_design()
unusedFunction:fpga.c:104
// Skip all memory issues since they should be handled by ivl_alloc.h
nullPointerOutOfMemory

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2003-2010 Stephen Williams (steve@icarus.com)
* Copyright (c) 2003-2026 Stephen Williams (steve@icarus.com)
*
* This source code is free software; you can redistribute it
* and/or modify it in source code form under the terms of the GNU
@ -431,7 +431,7 @@ void edif_print(FILE*fd, edif_t edf)
edif_cell_t cell;
edif_cellref_t ref;
edif_joint_t jnt;
struct cellref_property_*prp;
const struct cellref_property_*prp;
unsigned idx;
fprintf(fd, "(edif %s\n", edf->name);
@ -460,7 +460,7 @@ void edif_print(FILE*fd, edif_t edf)
" (interface");
for (idx = 0 ; idx < cell->nports ; idx += 1) {
struct __cell_port*pp = cell->ports + idx;
const struct __cell_port*pp = cell->ports + idx;
fprintf(fd, "\n (port %s", pp->name);
switch (pp->dir) {
case IVL_SIP_INPUT:
@ -559,7 +559,7 @@ void edif_print(FILE*fd, edif_t edf)
/* Display all the joints. */
idx = 0;
for (jnt = edf->nexa ; jnt ; jnt = jnt->next, idx += 1) {
struct joint_cell_*jc;
const struct joint_cell_*jc;
fprintf(fd, "(net ");
if (jnt->name != 0)

View File

@ -56,6 +56,8 @@ distclean: clean
cppcheck: $(O:.o=.c)
cppcheck --enable=all --std=c99 --std=c++11 -f \
--check-level=exhaustive \
--suppressions-list=$(srcdir)/../cppcheck-global.sup \
--suppressions-list=$(srcdir)/cppcheck.sup \
--relative-paths=$(srcdir) $(INCLUDE_PATH) $^

View File

@ -1,5 +1,2 @@
// These are the global access functions called from the compiler so they
// are not used here.
// target_design()
unusedFunction:imain.c:59
// Skip all memory issues since they should be handled by ivl_alloc.h
nullPointerOutOfMemory

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2000-2010 Stephen Williams (steve@icarus.com)
* Copyright (c) 2000-2026 Stephen Williams (steve@icarus.com)
*
* This source code is free software; you can redistribute it
* and/or modify it in source code form under the terms of the GNU
@ -64,7 +64,7 @@ static term_t** build_expr(ivl_nexus_t nex)
/* First look to see if I'm connected to an input pin. If so,
then this expression is done. */
for (idx = 0 ; idx < pins ; idx += 1) {
struct pal_bind_s*pin = bind_pin + idx;
const struct pal_bind_s*pin = bind_pin + idx;
if ((nex == pin->nexus) && (pin->sop == 0)) {
return expr;
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2000 Stephen Williams (steve@icarus.com)
* Copyright (c) 2000-2026 Stephen Williams (steve@icarus.com)
*
* This source code is free software; you can redistribute it
* and/or modify it in source code form under the terms of the GNU
@ -61,8 +61,7 @@ int fit_registers(ivl_scope_t scope, void*x)
for (q = 0 ; q < wid ; q += 1) {
rc = scan_ff_q(lpm, q);
if (rc != 0)
return rc;
assert(rc == 0);
}
}

View File

@ -68,7 +68,7 @@ cppcheck: $(O:.o=.cc)
-UYY_USER_INIT \
-UYYPARSE_PARAM -UYYPRINT -Ushort -Usize_t -Uyyoverflow \
-UYYTYPE_INT8 -UYYTYPE_INT16 -UYYTYPE_UINT8 -UYYTYPE_UINT16 \
-UYYSTYPE -U__SIZE_TYPE__ -Ufree \
-UYYSTYPE -U__SIZE_TYPE__ -Ufree -Umalloc \
--relative-paths=$(srcdir) $(INCLUDE_PATH) $^
Makefile: $(srcdir)/Makefile.in ../config.status

View File

@ -6,3 +6,18 @@ unusedFunction:pcb.cc:52
// target_query()
unusedFunction:pcb.cc:84
// Errors/limitations in the generated yacc and lex files
duplicateBreak:fp.lex
constParameterPointer:fp.cc
invalidPrintfArgType_sint:fp.cc
knownConditionTrueFalse:fp.cc
syntaxError:fp.cc
unsignedPositive:fp.cc
constVariablePointer:fp_lex.cc
cstyleCast:fp_lex.cc
nullPointer:fp_lex.cc
redundantInitialization:fp_lex.cc
syntaxError:fp_lex.cc
unusedFunction:fp_lex.cc
unusedStructMember:fp_lex.cc

View File

@ -5,7 +5,7 @@ nullPointerOutOfMemory:logic_lpm.c:2247 // strdup @ 2244
nullPointerOutOfMemory:misc.c:39 // malloc @ 38
nullPointerOutOfMemory:misc.c:794 // malloc @ 793
nullPointerOutOfMemory:misc.c:795 // malloc @ 793
nullPointerOutOfMemory:numbers.c:351 // strdup @ 348
nullPointerOutOfMemory:numbers.c:362 // strdup @ 348
nullPointerOutOfMemory:scope.c:301 // malloc @ 300
nullPointerOutOfMemory:scope.c:302 // malloc @ 300
nullPointerOutOfMemory:scope.c:303 // malloc @ 300
@ -16,8 +16,8 @@ nullPointerOutOfMemory:scope.c:993 // malloc @ 990
nullPointerOutOfMemory:scope.c:994 // malloc @ 990
nullPointerOutOfMemory:scope.c:995 // malloc @ 990
nullPointerOutOfMemory:scope.c:996 // malloc @ 990
nullPointerOutOfMemory:stmt.c:777 // malloc @ 775
nullPointerOutOfMemory:stmt.c:778 // malloc @ 775
nullPointerOutOfMemory:stmt.c:830 // malloc @ 775
nullPointerOutOfMemory:stmt.c:831 // malloc @ 775
memleakOnRealloc:scope.c:175
memleakOnRealloc:scope.c:1021
memleakOnRealloc:scope.c:1067

View File

@ -431,7 +431,7 @@ static void emit_array_pattern(ivl_scope_t scope, ivl_lval_t lval,
/* For an array the LSB/MSB order is not important.
* They are always accessed from base counting up. */
lsb = ivl_signal_array_base(var);
fprintf(vlog_out, "[%d] = ", lsb+idx);
fprintf(vlog_out, "[%u] = ", lsb+idx);
wid = ivl_lval_width(lval);
emit_expr(scope, expr, wid, 1, 0, 0);
fprintf(vlog_out, ";\n");

View File

@ -254,7 +254,6 @@ verinum::verinum(double val, bool)
if (nwords == 0) {
unsigned long bits = (unsigned long) fraction;
fraction = fraction - (double) bits;
for (unsigned idx = 0; idx < nbits_; idx += 1) {
bits_[idx] = (bits&1) ? V1 : V0;
bits >>= 1;

View File

@ -92,7 +92,7 @@ cppcheck: $(O:.o=.cc)
-UYY_USER_INIT \
-UYYPARSE_PARAM -UYYPRINT -Ushort -Usize_t -Uyyoverflow \
-UYYTYPE_INT8 -UYYTYPE_INT16 -UYYTYPE_UINT8 -UYYTYPE_UINT16 \
-UYYSTYPE -U__SIZE_TYPE__ -Ufree \
-UYYSTYPE -U__SIZE_TYPE__ -Ufree -Umalloc \
$(INCLUDE_PATH) $^
Makefile: $(srcdir)/Makefile.in

View File

@ -2,6 +2,12 @@
// text is used in strchr()/strrchr() which take a char* not a const char*
constParameterPointer:lexor.lex:698
// We only use a StringHeap or a StringHepLex
duplInheritedMember:libmisc/StringHeap.h:99
duplInheritedMember:libmisc/StringHeap.h:100
duplInheritedMember:libmisc/StringHeap.cc:160
duplInheritedMember:libmisc/StringHeap.cc:182
// Skip the use STL messages
useStlAlgorithm