Remove some cppcheck warnings, etc.

This commit is contained in:
Cary R 2012-11-12 18:13:41 -08:00
parent 78128dd95d
commit 15fb58f8e4
18 changed files with 39 additions and 36 deletions

View File

@ -172,8 +172,8 @@ endif
rm -rf autom4te.cache rm -rf autom4te.cache
cppcheck: $(O:.o=.cc) $(srcdir)/dosify.c $(srcdir)/version.c cppcheck: $(O:.o=.cc) $(srcdir)/dosify.c $(srcdir)/version.c
cppcheck --enable=all -f --suppressions $(srcdir)/cppcheck.sup \ cppcheck --enable=all -f --suppressions-list=$(srcdir)/cppcheck.sup \
$(INCLUDE_PATH) $^ --relative-paths=$(srcdir) $(INCLUDE_PATH) $^
cppcheck-all: cppcheck-all:
$(foreach dir,$(SUBDIRS),$(MAKE) -C $(dir) cppcheck && ) true $(foreach dir,$(SUBDIRS),$(MAKE) -C $(dir) cppcheck && ) true

View File

@ -1,3 +1,3 @@
// These are correct and are used to find the base (zero) pin. // These are correct and are used to find the base (zero) pin.
thisSubtraction:netlist.h:4326 thisSubtraction:netlist.h:4347
thisSubtraction:netlist.h:4335 thisSubtraction:netlist.h:4356

View File

@ -195,7 +195,6 @@ int yywrap()
void switch_to_command_file(const char *file) void switch_to_command_file(const char *file)
{ {
char path[4096]; char path[4096];
char *cp;
if (cmdfile_stack_ptr >= MAX_CMDFILE_DEPTH) { if (cmdfile_stack_ptr >= MAX_CMDFILE_DEPTH) {
fprintf(stderr, "Error: command files nested too deeply (%d) " fprintf(stderr, "Error: command files nested too deeply (%d) "
@ -213,6 +212,7 @@ void switch_to_command_file(const char *file)
* file name. * file name.
*/ */
if (file[0] != '/') { if (file[0] != '/') {
char *cp;
strcpy(path, current_file); strcpy(path, current_file);
cp = strrchr(path, '/'); cp = strrchr(path, '/');
if (cp == 0) strcpy(path, file); /* A base file. */ if (cp == 0) strcpy(path, file); /* A base file. */

View File

@ -2450,8 +2450,8 @@ unsigned PEIdent::test_width(Design*des, NetScope*scope, width_mode_t&mode)
perm_string method_name = peek_tail_name(use_path); perm_string method_name = peek_tail_name(use_path);
use_path.pop_back(); use_path.pop_back();
found_in = symbol_search(this, des, scope, use_path, ivl_assert(*this, net == 0);
net, par, eve, ex1, ex2); symbol_search(this, des, scope, use_path, net, par, eve, ex1, ex2);
// Check to see if we have a net and if so is it a structure? // Check to see if we have a net and if so is it a structure?
if (net != 0) { if (net != 0) {
@ -2641,8 +2641,8 @@ NetExpr* PEIdent::elaborate_expr(Design*des, NetScope*scope,
<< "Look for base_path " << use_path << "Look for base_path " << use_path
<< " for member " << member_comp << "." << endl; << " for member " << member_comp << "." << endl;
found_in = symbol_search(this, des, scope, use_path, ivl_assert(*this, net == 0);
net, par, eve, ex1, ex2); symbol_search(this, des, scope, use_path, net, par, eve, ex1, ex2);
// Check to see if we have a net and if so is it an // Check to see if we have a net and if so is it an
// enumeration? If so then check to see if this is an // enumeration? If so then check to see if this is an
@ -3807,6 +3807,7 @@ NetExpr* PEIdent::elaborate_expr_net_bit_(Design*des, NetScope*scope,
unsigned long lwid; unsigned long lwid;
long idx; long idx;
rc = net->sig()->sb_to_slice(prefix_indices, msv, idx, lwid); rc = net->sig()->sb_to_slice(prefix_indices, msv, idx, lwid);
ivl_assert(*this, rc);
// Make an expression out of the index // Make an expression out of the index
NetEConst*idx_c = new NetEConst(verinum(idx)); NetEConst*idx_c = new NetEConst(verinum(idx));

View File

@ -773,7 +773,7 @@ void PGBuiltin::elaborate(Design*des, NetScope*scope) const
NetExpr* rise_time, *fall_time, *decay_time; NetExpr* rise_time, *fall_time, *decay_time;
eval_delays(des, scope, rise_time, fall_time, decay_time); eval_delays(des, scope, rise_time, fall_time, decay_time);
struct attrib_list_t*attrib_list = 0; struct attrib_list_t*attrib_list;
unsigned attrib_list_n = 0; unsigned attrib_list_n = 0;
attrib_list = evaluate_attributes(attributes, attrib_list_n, attrib_list = evaluate_attributes(attributes, attrib_list_n,
des, scope); des, scope);
@ -1614,7 +1614,7 @@ void PGModule::elaborate_mod_(Design*des, Module*rmod, NetScope*scope) const
assert(sig); assert(sig);
#ifndef NDEBUG #ifndef NDEBUG
if ((prts.size() >= 1) if ((! prts.empty())
&& (prts[0]->port_type() != NetNet::PINPUT)) { && (prts[0]->port_type() != NetNet::PINPUT)) {
assert(sig->type() != NetNet::REG); assert(sig->type() != NetNet::REG);
} }
@ -1938,7 +1938,7 @@ void PGModule::elaborate_udp_(Design*des, PUdp*udp, NetScope*scope) const
net->fall_time(fall_expr); net->fall_time(fall_expr);
net->decay_time(decay_expr); net->decay_time(decay_expr);
struct attrib_list_t*attrib_list = 0; struct attrib_list_t*attrib_list;
unsigned attrib_list_n = 0; unsigned attrib_list_n = 0;
attrib_list = evaluate_attributes(attributes, attrib_list_n, attrib_list = evaluate_attributes(attributes, attrib_list_n,
des, scope); des, scope);
@ -2815,7 +2815,7 @@ NetProc* PCase::elaborate(Design*des, NetScope*scope) const
a separate case for each. (Yes, the statement a separate case for each. (Yes, the statement
will be elaborated again for each.) */ will be elaborated again for each.) */
PExpr*cur_expr = *idx_expr; PExpr*cur_expr = *idx_expr;
NetExpr*gu = 0; NetExpr*gu;
NetProc*st = 0; NetProc*st = 0;
assert(cur_expr); assert(cur_expr);
gu = elab_and_eval(des, scope, cur_expr, -1); gu = elab_and_eval(des, scope, cur_expr, -1);
@ -4282,7 +4282,7 @@ bool PProcess::elaborate(Design*des, NetScope*scope) const
// Evaluate the attributes for this process, if there // Evaluate the attributes for this process, if there
// are any. These attributes are to be attached to the // are any. These attributes are to be attached to the
// NetProcTop object. // NetProcTop object.
struct attrib_list_t*attrib_list = 0; struct attrib_list_t*attrib_list;
unsigned attrib_list_n = 0; unsigned attrib_list_n = 0;
attrib_list = evaluate_attributes(attributes, attrib_list_n, des, scope); attrib_list = evaluate_attributes(attributes, attrib_list_n, des, scope);

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2008,2011 Stephen Williams (steve@icarus.com) * Copyright (c) 2008-2012 Stephen Williams (steve@icarus.com)
* *
* This source code is free software; you can redistribute it * This source code is free software; you can redistribute it
* and/or modify it in source code form under the terms of the GNU * and/or modify it in source code form under the terms of the GNU
@ -55,7 +55,7 @@ bool AProcess::elaborate(Design*des, NetScope*scope) const
// Evaluate the attributes for this process, if there // Evaluate the attributes for this process, if there
// are any. These attributes are to be attached to the // are any. These attributes are to be attached to the
// NetProcTop object. // NetProcTop object.
struct attrib_list_t*attrib_list = 0; struct attrib_list_t*attrib_list;
unsigned attrib_list_n = 0; unsigned attrib_list_n = 0;
attrib_list = evaluate_attributes(attributes, attrib_list_n, des, scope); attrib_list = evaluate_attributes(attributes, attrib_list_n, des, scope);

View File

@ -24,6 +24,7 @@
# include <cassert> # include <cassert>
#ifdef CHECK_WITH_VALGRIND #ifdef CHECK_WITH_VALGRIND
# include "ivl_alloc.h"
static char **string_pool = NULL; static char **string_pool = NULL;
static unsigned string_pool_count = 0; static unsigned string_pool_count = 0;
#endif #endif

View File

@ -512,7 +512,7 @@ void NetNet::calculate_slice_widths_from_packed_dims_(void)
// Special case: There are no actual packed dimensions, so // Special case: There are no actual packed dimensions, so
// build up a fake dimension of "1". // build up a fake dimension of "1".
if (slice_dims_.size() == 0) { if (slice_dims_.empty()) {
slice_wids_.resize(1); slice_wids_.resize(1);
slice_wids_[0] = net_type_->packed_width(); slice_wids_[0] = net_type_->packed_width();
return; return;
@ -520,7 +520,7 @@ void NetNet::calculate_slice_widths_from_packed_dims_(void)
slice_wids_.resize(slice_dims_.size()); slice_wids_.resize(slice_dims_.size());
ivl_assert(*this, slice_wids_.size() >= 1); ivl_assert(*this, ! slice_wids_.empty());
slice_wids_[0] = netrange_width(slice_dims_); slice_wids_[0] = netrange_width(slice_dims_);
vector<netrange_t>::const_iterator cur = slice_dims_.begin(); vector<netrange_t>::const_iterator cur = slice_dims_.begin();
for (size_t idx = 1 ; idx < slice_wids_.size() ; idx += 1) { for (size_t idx = 1 ; idx < slice_wids_.size() ; idx += 1) {
@ -865,7 +865,7 @@ long NetNet::sb_to_idx(const list<long>&indices, long sb) const
// The acc_off is the possition within the innermost // The acc_off is the possition within the innermost
// dimension. If this is a multi-dimension packed array then // dimension. If this is a multi-dimension packed array then
// we need to add in the canonical address of the current slice. // we need to add in the canonical address of the current slice.
if (indices.size() >= 1) { if (! indices.empty()) {
list<long>::const_iterator icur = indices.end(); list<long>::const_iterator icur = indices.end();
do { do {
-- icur; -- icur;

View File

@ -1190,9 +1190,9 @@ NetExpr*collapse_array_exprs(Design*des, NetScope*scope,
// First elaborate all the expressions as far as possible. // First elaborate all the expressions as far as possible.
list<NetExpr*> exprs; list<NetExpr*> exprs;
list<long> exprs_const; list<long> exprs_const;
bool flag = indices_to_expressions(des, scope, loc, indices, indices_to_expressions(des, scope, loc, indices,
net->packed_dimensions(), net->packed_dimensions(),
false, exprs, exprs_const); false, exprs, exprs_const);
ivl_assert(*loc, exprs.size() == net->packed_dimensions()); ivl_assert(*loc, exprs.size() == net->packed_dimensions());
// Special Case: there is only 1 packed dimension, so the // Special Case: there is only 1 packed dimension, so the

View File

@ -22,13 +22,13 @@
using namespace std; using namespace std;
netvector_t::netvector_t(ivl_variable_type_t type, long msb, long lsb) netvector_t::netvector_t(ivl_variable_type_t type, long msb, long lsb)
: type_(type), signed_(false) : type_(type), signed_(false), isint_(false), is_scalar_(false)
{ {
packed_dims_.push_back(netrange_t(msb,lsb)); packed_dims_.push_back(netrange_t(msb,lsb));
} }
netvector_t::netvector_t(ivl_variable_type_t type) netvector_t::netvector_t(ivl_variable_type_t type)
: type_(type), signed_(false) : type_(type), signed_(false), isint_(false), is_scalar_(false)
{ {
} }

View File

@ -74,7 +74,8 @@ class netvector_t : public ivl_type_s {
inline netvector_t::netvector_t(const std::vector<netrange_t>&packed, inline netvector_t::netvector_t(const std::vector<netrange_t>&packed,
ivl_variable_type_t type) ivl_variable_type_t type)
: packed_dims_(packed), type_(type), signed_(false) : packed_dims_(packed), type_(type), signed_(false), isint_(false),
is_scalar_(false)
{ {
} }

View File

@ -2525,7 +2525,7 @@ void pform_set_localparam(const struct vlltype&loc,
error_count += 1; error_count += 1;
} }
if ((pform_cur_module.size() > 0) && if ((! pform_cur_module.empty()) &&
(scope == pform_cur_module.front()) && (scope == pform_cur_module.front()) &&
(pform_cur_module.front()->specparams.find(name) != pform_cur_module.front()->specparams.end())) { (pform_cur_module.front()->specparams.find(name) != pform_cur_module.front()->specparams.end())) {
LineInfo tloc; LineInfo tloc;

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2003-2010 Stephen Williams (steve@icarus.com) * Copyright (c) 2003-2012 Stephen Williams (steve@icarus.com)
* Copyright CERN 2012 / Stephen Williams (steve@icarus.com) * Copyright CERN 2012 / Stephen Williams (steve@icarus.com)
* *
* This source code is free software; you can redistribute it * This source code is free software; you can redistribute it
@ -79,7 +79,7 @@ bool symbol_search(const LineInfo*li, Design*des, NetScope*scope,
// If there are components ahead of the tail, symbol_search // If there are components ahead of the tail, symbol_search
// recursively. Ideally, the result is a scope that we search // recursively. Ideally, the result is a scope that we search
// for the tail key, but there are other special cases as well. // for the tail key, but there are other special cases as well.
if (path.size() > 0) { if (! path.empty()) {
symbol_search_results recurse; symbol_search_results recurse;
bool flag = symbol_search(li, des, scope, path, &recurse, start_scope); bool flag = symbol_search(li, des, scope, path, &recurse, start_scope);
if (! flag) if (! flag)

View File

@ -419,7 +419,7 @@ static void draw_vpi_taskfunc_args(const char*call_string,
buffer[0] = 0; buffer[0] = 0;
break; break;
default: default:
fprintf(vvp_out, "\nXXXX Unexpected argument: call_string=<%s>, arg=%d, type=%d\n", fprintf(vvp_out, "\nXXXX Unexpected argument: call_string=<%s>, arg=%u, type=%d\n",
call_string, idx, ivl_expr_value(expr)); call_string, idx, ivl_expr_value(expr));
fflush(vvp_out); fflush(vvp_out);
assert(0); assert(0);

View File

@ -95,8 +95,8 @@ distclean: clean
rm -f vpi_config.h stamp-vpi_config-h rm -f vpi_config.h stamp-vpi_config-h
cppcheck: $(O:.o=.c) $(OPP:.o=.cc) $(M:.o=.c) $(V:.o=.c) cppcheck: $(O:.o=.c) $(OPP:.o=.cc) $(M:.o=.c) $(V:.o=.c)
cppcheck --enable=all -f --suppressions $(srcdir)/cppcheck.sup \ cppcheck --enable=all -f --suppressions-list=$(srcdir)/cppcheck.sup \
$(INCLUDE_PATH) $^ --relative-paths=$(srcdir) $(INCLUDE_PATH) $^
Makefile: $(srcdir)/Makefile.in ../config.status Makefile: $(srcdir)/Makefile.in ../config.status
cd ..; ./config.status --file=vpi/$@ cd ..; ./config.status --file=vpi/$@

View File

@ -1231,7 +1231,7 @@ static PLI_INT32 strobe_cb(p_cb_data cb)
* Which has the same basic effect. */ * Which has the same basic effect. */
if ((! IS_MCD(info->fd_mcd) && vpi_get_file(info->fd_mcd) != NULL) || if ((! IS_MCD(info->fd_mcd) && vpi_get_file(info->fd_mcd) != NULL) ||
( IS_MCD(info->fd_mcd) && my_mcd_printf(info->fd_mcd, "") != EOF)) { ( IS_MCD(info->fd_mcd) && my_mcd_printf(info->fd_mcd, "") != EOF)) {
char* result = NULL; char* result;
unsigned int size, location=0; unsigned int size, location=0;
/* Because %u and %z may put embedded NULL characters into the /* Because %u and %z may put embedded NULL characters into the
* returned string strlen() may not match the real size! */ * returned string strlen() may not match the real size! */

View File

@ -103,8 +103,8 @@ distclean: clean
rm -f stamp-config-h config.h rm -f stamp-config-h config.h
cppcheck: $(O:.o=.cc) libvpi.c draw_tt.c cppcheck: $(O:.o=.cc) libvpi.c draw_tt.c
cppcheck --enable=all -f --suppressions $(srcdir)/cppcheck.sup \ cppcheck --enable=all -f --suppressions-list=$(srcdir)/cppcheck.sup \
$(INCLUDE_PATH) $^ --relative-paths=$(srcdir) $(INCLUDE_PATH) $^
Makefile: $(srcdir)/Makefile.in Makefile: $(srcdir)/Makefile.in
cd ..; ./config.status --file=vvp/$@ cd ..; ./config.status --file=vvp/$@

View File

@ -103,7 +103,7 @@ struct vthread_s {
public: public:
inline double pop_real(void) inline double pop_real(void)
{ {
assert(stack_real_.size() > 0); assert(! stack_real_.empty());
double val = stack_real_.back(); double val = stack_real_.back();
stack_real_.pop_back(); stack_real_.pop_back();
return val; return val;
@ -136,7 +136,7 @@ struct vthread_s {
public: public:
inline string pop_str(void) inline string pop_str(void)
{ {
assert(stack_str_.size() > 0); assert(! stack_str_.empty());
string val = stack_str_.back(); string val = stack_str_.back();
stack_str_.pop_back(); stack_str_.pop_back();
return val; return val;