Skip to content

Commit 3c8a8a9

Browse files
committed
Add vpi files to cppcheck and cleanup
1 parent d1982fc commit 3c8a8a9

11 files changed

Lines changed: 49 additions & 29 deletions

‎cppcheck.sup‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ constVariablePointer:main.cc:438
1515
constVariablePointer:main.cc:688
1616

1717
// const auto should be const
18-
constVariablePointer:elab_expr.cc:641
19-
constVariablePointer:elab_expr.cc:644
20-
constVariablePointer:elab_expr.cc:713
21-
constVariablePointer:elab_expr.cc:4296
18+
constVariablePointer:elab_expr.cc:643
19+
constVariablePointer:elab_expr.cc:646
20+
constVariablePointer:elab_expr.cc:715
21+
constVariablePointer:elab_expr.cc:4476
2222
constVariablePointer:elab_lval.cc:1149
2323
constVariablePointer:elab_scope.cc:1538
24-
constVariablePointer:parse.y:5388
24+
constVariablePointer:parse.y:5389
2525

2626
// The reference cannot be const since it is updated in the calling function.
2727
constParameterReference:net_udp.cc:37
@@ -40,7 +40,7 @@ uninitMemberVar:t-dll.cc:41
4040
uninitMemberVar:t-dll.cc:109
4141

4242
// By convention we put statics at the top scope.
43-
variableScope:pform.cc:3634
43+
variableScope:pform.cc:3635
4444

4545
// These are correct and are used to find the base (zero) pin.
4646
thisSubtraction:netlist.h:5384

‎elab_expr.cc‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4473,7 +4473,7 @@ static unsigned int evaluate_cast_size(Design *des, NetScope *scope,
44734473
{
44744474
unsigned int width = 0;
44754475
auto size_expr = elab_and_eval(des, scope, target, -1, true);
4476-
auto size_const = dynamic_cast<NetEConst *>(size_expr);
4476+
const auto size_const = dynamic_cast<NetEConst *>(size_expr);
44774477
if (size_const && !size_const->value().is_negative())
44784478
width = size_const->value().as_ulong();
44794479
delete size_expr;

‎vpi/Makefile.in‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,8 @@ distclean: clean
102102

103103
# The -U flag is used to skip checking paths that depend on that define having
104104
# an explicit value (i.e. the define is expected to be real code).
105-
cppcheck: $(O:.o=.c) $(OPP:.o=.cc) $(M:.o=.c) $(V:.o=.c)
105+
cppcheck: $(O:.o=.c) $(OPP:.o=.cc) $(V2005:.o=.c) $(VA_MATH:.o=.c) $(V2009:.o=.c) \
106+
$(VHDL_SYS:.o=.c) $(VHDL_TEXTIO:.o=.c) $(VPI_DEBUG:.o=.c)
106107
cppcheck --enable=all --std=c99 --std=c++11 -f \
107108
--check-level=exhaustive \
108109
--suppressions-list=$(srcdir)/../cppcheck-global.sup \

‎vpi/cppcheck.sup‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,16 @@ constParameterCallback:sys_sdf.c:437
4848
constParameterCallback:sys_time.c:25
4949
constParameterCallback:sys_time.c:81
5050
constParameterCallback:table_mod.c:663
51+
constParameterCallback:va_math.c:193
52+
constParameterCallback:va_math.c:270
53+
constParameterCallback:v2005_math.c:166
54+
constParameterCallback:v2005_math.c:243
55+
constParameterCallback:v2009_enum.c:238
56+
constParameterCallback:v2009_string.c:263
57+
constParameterCallback:v2009_string.c:338
58+
constParameterCallback:vhdl_table.c:95
59+
constParameterCallback:vhdl_table.c:155
60+
constParameterCallback:vhdl_table.c:200
5161

5262
// Unused functions.
5363
unusedFunction:sys_sdf.c:60

‎vpi/v2009_array.c‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2013-2021 Cary R. (cygcary@yahoo.com)
2+
* Copyright (C) 2013-2026 Cary R. (cygcary@yahoo.com)
33
* Copyright (C) 2014 Stephen Williams (steve@icarus.com)
44
* Copyright (C) 2014 CERN
55
* @author Maciej Suminski (maciej.suminski@cern.ch)
@@ -266,8 +266,6 @@ void v2009_array_register(void)
266266

267267
tf_data.type = vpiSysFunc;
268268
tf_data.sysfunctype = vpiIntFunc;
269-
tf_data.calltf = 0;
270-
tf_data.compiletf = func_not_implemented_compiletf;;
271269
tf_data.sizetf = 0;
272270

273271
tf_data.tfname = "$high";
@@ -301,16 +299,22 @@ void v2009_array_register(void)
301299
/* These functions are not currently implemented. */
302300
tf_data.tfname = "$dimensions";
303301
tf_data.user_data = "$dimensions";
302+
tf_data.compiletf = func_not_implemented_compiletf;;
303+
tf_data.calltf = 0;
304304
res = vpi_register_systf(&tf_data);
305305
vpip_make_systf_system_defined(res);
306306

307307
tf_data.tfname = "$unpacked_dimensions";
308308
tf_data.user_data = "$unpacked_dimensions";
309+
tf_data.compiletf = func_not_implemented_compiletf;;
310+
tf_data.calltf = 0;
309311
res = vpi_register_systf(&tf_data);
310312
vpip_make_systf_system_defined(res);
311313

312314
tf_data.tfname = "$increment";
313315
tf_data.user_data = "$increment";
316+
tf_data.compiletf = func_not_implemented_compiletf;;
317+
tf_data.calltf = 0;
314318
res = vpi_register_systf(&tf_data);
315319
vpip_make_systf_system_defined(res);
316320
}

‎vpi/v2009_bitvec.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2018-2021 Cary R. (cygcary@yahoo.com)
2+
* Copyright (C) 2018-2026 Cary R. (cygcary@yahoo.com)
33
*
44
* This program is free software; you can redistribute it and/or modify
55
* it under the terms of the GNU General Public License as published by
@@ -81,7 +81,7 @@ static PLI_INT32 countbits_compiletf(ICARUS_VPI_CONST PLI_BYTE8 *name)
8181
}
8282

8383
/* Count the number of bits in the expression that match the search bits. */
84-
static PLI_INT32 count_bits_in_expr(vpiHandle expr_arg, char search[4])
84+
static PLI_INT32 count_bits_in_expr(vpiHandle expr_arg, const char search[4])
8585
{
8686
s_vpi_value val;
8787
PLI_INT32 result;

‎vpi/v2009_string.c‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2012-2025 Stephen Williams (steve@icarus.com)
2+
* Copyright (c) 2012-2026 Stephen Williams (steve@icarus.com)
33
*
44
* This source code is free software; you can redistribute it
55
* and/or modify it in source code form under the terms of the GNU
@@ -73,7 +73,7 @@ static PLI_INT32 two_arg_compiletf(ICARUS_VPI_CONST PLI_BYTE8*name)
7373
}
7474

7575
arg = vpi_scan(argv);
76-
if (argv == 0) {
76+
if (arg == 0) {
7777
vpi_printf("ERROR: %s:%d: ", vpi_get_str(vpiFile, callh),
7878
(int)vpi_get(vpiLineNo, callh));
7979
vpi_printf("%s missing object argument.\n", name);
@@ -83,7 +83,7 @@ static PLI_INT32 two_arg_compiletf(ICARUS_VPI_CONST PLI_BYTE8*name)
8383
}
8484

8585
arg = vpi_scan(argv);
86-
if (argv == 0) {
86+
if (arg == 0) {
8787
vpi_printf("ERROR: %s:%d: ", vpi_get_str(vpiFile, callh),
8888
(int)vpi_get(vpiLineNo, callh));
8989
vpi_printf("%s missing method argument.\n", name);
@@ -468,6 +468,7 @@ void v2009_string_register(void)
468468
tf_data.sizetf = 0;
469469
tf_data.user_data = "10";
470470
res = vpi_register_systf(&tf_data);
471+
vpip_make_systf_system_defined(res);
471472

472473
tf_data.type = vpiSysTask;
473474
tf_data.tfname = "$ivl_string_method$hextoa";
@@ -476,6 +477,7 @@ void v2009_string_register(void)
476477
tf_data.sizetf = 0;
477478
tf_data.user_data = "16";
478479
res = vpi_register_systf(&tf_data);
480+
vpip_make_systf_system_defined(res);
479481

480482
tf_data.type = vpiSysTask;
481483
tf_data.tfname = "$ivl_string_method$octtoa";
@@ -484,6 +486,7 @@ void v2009_string_register(void)
484486
tf_data.sizetf = 0;
485487
tf_data.user_data = "8";
486488
res = vpi_register_systf(&tf_data);
489+
vpip_make_systf_system_defined(res);
487490

488491
tf_data.type = vpiSysTask;
489492
tf_data.tfname = "$ivl_string_method$bintoa";
@@ -492,6 +495,7 @@ void v2009_string_register(void)
492495
tf_data.sizetf = 0;
493496
tf_data.user_data = "2";
494497
res = vpi_register_systf(&tf_data);
498+
vpip_make_systf_system_defined(res);
495499

496500
tf_data.type = vpiSysTask;
497501
tf_data.tfname = "$ivl_string_method$realtoa";
@@ -500,6 +504,5 @@ void v2009_string_register(void)
500504
tf_data.sizetf = 0;
501505
tf_data.user_data = "$ivl_string_method$realtoa";
502506
res = vpi_register_systf(&tf_data);
503-
504507
vpip_make_systf_system_defined(res);
505508
}

‎vpi/vhdl_table.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2011-2025 Stephen Williams (steve@icarus.com)
2+
* Copyright (c) 2011-2026 Stephen Williams (steve@icarus.com)
33
*
44
* This source code is free software; you can redistribute it
55
* and/or modify it in source code form under the terms of the GNU
@@ -157,7 +157,7 @@ static PLI_INT32 ivlh_attribute_event_calltf(ICARUS_VPI_CONST PLI_BYTE8*data)
157157
event_type_t type = (event_type_t)(uintptr_t)data;
158158
vpiHandle sys = vpi_handle(vpiSysTfCall, 0);
159159
struct t_vpi_value rval;
160-
struct monitor_data*mon;
160+
const struct monitor_data*mon;
161161

162162
rval.format = vpiScalarVal;
163163

‎vpi/vhdl_textio.c‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015-2025 CERN
2+
* Copyright (c) 2015-2026 CERN
33
* @author Maciej Suminski <maciej.suminski@cern.ch>
44
*
55
* This source code is free software; you can redistribute it
@@ -152,7 +152,7 @@ static int read_vector(const char *string, s_vpi_value *val, vpiHandle var)
152152

153153
/* Skip spaces in the beginning */
154154
int skipped = 0;
155-
while(*string && *string == ' ') {
155+
while(*string == ' ') {
156156
--len;
157157
++string;
158158
++skipped;
@@ -654,7 +654,7 @@ static PLI_INT32 ivlh_read_calltf(ICARUS_VPI_CONST PLI_BYTE8*name)
654654
s_vpi_value val;
655655
PLI_INT32 type, format, dest_size;
656656
char *string = 0;
657-
unsigned int processed_chars = 0, fail = 0;
657+
int processed_chars = 0, fail = 0;
658658

659659
/* Get the string */
660660
stringh = vpi_scan(argv);
@@ -751,11 +751,12 @@ static PLI_INT32 ivlh_read_calltf(ICARUS_VPI_CONST PLI_BYTE8*name)
751751
break;
752752
}
753753

754-
if(processed_chars == 0) {
754+
if(processed_chars <= 0) {
755755
show_error_line(callh);
756756
vpi_printf("%s could not read a valid value.\n", name);
757757
fail = 1;
758-
} else if(val.format == vpiStringVar && processed_chars == STRING_BUF_SIZE) {
758+
} else if(val.format == vpiStringVar &&
759+
(size_t)processed_chars == STRING_BUF_SIZE) {
759760
show_warning_line(callh);
760761
vpi_printf("%s has reached the buffer limit, part of the "
761762
"processed string might have been skipped.\n", name);
@@ -999,8 +1000,6 @@ static PLI_INT32 ivlh_write_calltf(ICARUS_VPI_CONST PLI_BYTE8*name)
9991000

10001001
static void vhdl_register(void)
10011002
{
1002-
vpiHandle res;
1003-
10041003
s_vpi_systf_data tf_data[] = {
10051004
{ vpiSysTask, 0, "$ivlh_file_open",
10061005
ivlh_file_open_calltf, ivlh_file_open_compiletf, 0,
@@ -1024,6 +1023,7 @@ static void vhdl_register(void)
10241023
};
10251024

10261025
for(unsigned int i = 0; i < sizeof(tf_data) / sizeof(s_vpi_systf_data); ++i) {
1026+
vpiHandle res;
10271027
res = vpi_register_systf(&tf_data[i]);
10281028
vpip_make_systf_system_defined(res);
10291029
}

‎vpi/vpi_debug.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2011-2014 Stephen Williams (steve@icarus.com)
2+
* Copyright (c) 2011-2026 Stephen Williams (steve@icarus.com)
33
*
44
* This source code is free software; you can redistribute it
55
* and/or modify it in source code form under the terms of the GNU
@@ -96,7 +96,7 @@ static PLI_INT32 vpi_tree_calltf(ICARUS_VPI_CONST PLI_BYTE8*name)
9696
return 0;
9797
}
9898

99-
void sys_register(void)
99+
static void sys_register(void)
100100
{
101101
s_vpi_systf_data tf_data;
102102
vpiHandle res;

0 commit comments

Comments
 (0)