From f07f6a26a8a303e168ea71bab9e4dbf0e94a4035 Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Sun, 3 Feb 2013 13:27:37 -0500 Subject: [PATCH] cppcheck fixes --- Makefile.in | 7 +++++-- include/verilated.cpp | 8 +++++--- include/verilated_dpi.cpp | 3 --- include/verilated_save.cpp | 2 ++ include/verilated_save.h | 6 +++--- include/verilated_vcd_c.cpp | 1 + include/verilated_vpi.h | 8 ++++---- src/V3Assert.cpp | 1 + src/V3Ast.cpp | 1 + src/V3Ast.h | 7 +++++-- src/V3Begin.cpp | 2 +- src/V3Const.cpp | 1 + src/V3Error.h | 2 +- src/V3LinkDot.cpp | 6 +++--- src/V3List.h | 6 +++--- src/V3Options.cpp | 6 +++--- src/V3Options.h | 4 ++-- src/V3Param.cpp | 4 ++-- src/V3SymTable.h | 4 ++-- src/V3Tristate.cpp | 2 +- src/V3Width.cpp | 2 +- src/verilog.y | 1 - test_regress/t/t_vpi_unimpl.pl | 0 23 files changed, 47 insertions(+), 37 deletions(-) mode change 100644 => 100755 test_regress/t/t_vpi_unimpl.pl diff --git a/Makefile.in b/Makefile.in index 0ca6b7219..a813dfe7f 100644 --- a/Makefile.in +++ b/Makefile.in @@ -398,14 +398,17 @@ endif # VERILATOR_AUTHOR_SITE endif +# Use --xml flag to see the cppcheck code to use for suppression CPPCHECK = cppcheck -CPPCHECK_FLAGS = --enable=all --inline-suppr --suppress=unusedScopedObject +CPPCHECK_FLAGS = --enable=all --inline-suppr --suppress=unusedScopedObject --suppress=cstyleCast +CPPCHECK_FLAGS += --xml CPPCHECK_CPP = $(wildcard $(srcdir)/include/*.cpp $(srcdir)/src/*.cpp) CPPCHECK_DEP = $(subst .cpp,.cppcheck,$(CPPCHECK_CPP)) +CPPCHECK_INC = -I$(srcdir)/include -I$(srcdir)/src/obj_dbg -I$(srcdir)/src cppcheck: $(CPPCHECK_DEP) %.cppcheck: %.cpp - $(CPPCHECK) $(CPPCHECK_FLAGS) -DVL_DEBUG=1 -I$(srcdir)/include -I$(srcdir)/src $< + $(CPPCHECK) $(CPPCHECK_FLAGS) -DVL_DEBUG=1 $(CPPCHECK_INC) $< ftp: info diff --git a/include/verilated.cpp b/include/verilated.cpp index 23e345cf0..7c4e83c3d 100644 --- a/include/verilated.cpp +++ b/include/verilated.cpp @@ -603,7 +603,7 @@ IData _vl_vsscanf(FILE* fp, // If a fscanf _vl_vsss_read(fp,floc,fromp, tmp, "0123456789+-xXzZ?_"); if (!tmp[0]) goto done; vlsint64_t ld; - sscanf(tmp,"%" VL_PRI64 "d",&ld); + sscanf(tmp,"%30" VL_PRI64 "d",&ld); VL_SET_WQ(owp,ld); break; } @@ -624,7 +624,7 @@ IData _vl_vsscanf(FILE* fp, // If a fscanf _vl_vsss_read(fp,floc,fromp, tmp, "0123456789+-xXzZ?_"); if (!tmp[0]) goto done; QData ld; - sscanf(tmp,"%" VL_PRI64 "u",&ld); + sscanf(tmp,"%30" VL_PRI64 "u",&ld); VL_SET_WQ(owp,ld); break; } @@ -977,7 +977,7 @@ IData VL_VALUEPLUSARGS_IW(int rbits, const char* prefixp, char fmt, WDataOutP rw break; case 'd': vlsint64_t ld; - sscanf(dp,"%" VL_PRI64 "d",&ld); + sscanf(dp,"%30" VL_PRI64 "d",&ld); VL_SET_WQ(rwp,ld); break; case 'b': @@ -1101,6 +1101,7 @@ VerilatedModule::~VerilatedModule() { //====================================================================== // VerilatedVar:: Methods +// cppcheck-suppress unusedFunction // Used by applications vluint32_t VerilatedVar::entSize() const { vluint32_t size = 1; switch (vltype()) { @@ -1197,6 +1198,7 @@ void VerilatedScope::varInsert(int finalize, const char* namep, void* datap, m_varsp->insert(make_pair(namep,var)); } +// cppcheck-suppress unusedFunction // Used by applications VerilatedVar* VerilatedScope::varFind(const char* namep) const { if (VL_LIKELY(m_varsp)) { VerilatedVarNameMap::iterator it = m_varsp->find(namep); diff --git a/include/verilated_dpi.cpp b/include/verilated_dpi.cpp index 715cda9aa..ba9650013 100644 --- a/include/verilated_dpi.cpp +++ b/include/verilated_dpi.cpp @@ -104,9 +104,6 @@ int svHigh(const svOpenArrayHandle h, int d) { int svIncrement(const svOpenArrayHandle h, int d) { _VL_SVDPI_UNIMP(); return 0; } -int svLength(const svOpenArrayHandle h, int d) { - _VL_SVDPI_UNIMP(); return 0; -} int svDimensions(const svOpenArrayHandle h) { _VL_SVDPI_UNIMP(); return 0; } diff --git a/include/verilated_save.cpp b/include/verilated_save.cpp index 1bc56eb7f..0694dca35 100644 --- a/include/verilated_save.cpp +++ b/include/verilated_save.cpp @@ -116,6 +116,7 @@ void VerilatedSave::open (const char* filenamep) { if (filenamep[0]=='|') { assert(0); // Not supported yet. } else { + // cppcheck-suppress duplicateExpression m_fd = ::open (filenamep, O_CREAT|O_WRONLY|O_TRUNC|O_LARGEFILE|O_NONBLOCK , 0666); if (m_fd<0) { @@ -137,6 +138,7 @@ void VerilatedRestore::open (const char* filenamep) { if (filenamep[0]=='|') { assert(0); // Not supported yet. } else { + // cppcheck-suppress duplicateExpression m_fd = ::open (filenamep, O_CREAT|O_RDONLY|O_LARGEFILE , 0666); if (m_fd<0) { diff --git a/include/verilated_save.h b/include/verilated_save.h index 7cc2e29a6..72cf890dc 100644 --- a/include/verilated_save.h +++ b/include/verilated_save.h @@ -109,7 +109,7 @@ protected: void trailer(); public: // CREATORS - VerilatedDeserialize() {} + VerilatedDeserialize() { m_endp = NULL; } virtual ~VerilatedDeserialize() { close(); } // METHODS inline VerilatedDeserialize& read (void* __restrict datap, size_t size) { @@ -146,7 +146,7 @@ private: public: // CREATORS - VerilatedSave() {} + VerilatedSave() { m_fd=-1; } virtual ~VerilatedSave() { close(); } // METHODS void open(const char* filenamep); ///< Open the file; call isOpen() to see if errors @@ -164,7 +164,7 @@ private: public: // CREATORS - VerilatedRestore() {} + VerilatedRestore() { m_fd=-1; } virtual ~VerilatedRestore() { close(); } // METHODS diff --git a/include/verilated_vcd_c.cpp b/include/verilated_vcd_c.cpp index ba6f99272..daac02927 100644 --- a/include/verilated_vcd_c.cpp +++ b/include/verilated_vcd_c.cpp @@ -141,6 +141,7 @@ void VerilatedVcd::openNext (bool incFilename) { if (m_filename[0]=='|') { assert(0); // Not supported yet. } else { + // cppcheck-suppress duplicateExpression m_fd = ::open (m_filename.c_str(), O_CREAT|O_WRONLY|O_TRUNC|O_LARGEFILE|O_NONBLOCK , 0666); if (m_fd<0) { diff --git a/include/verilated_vpi.h b/include/verilated_vpi.h index f31484b0c..fadf3e032 100644 --- a/include/verilated_vpi.h +++ b/include/verilated_vpi.h @@ -274,7 +274,7 @@ class VerilatedVpi { static VerilatedVpi s_s; // Singleton public: - VerilatedVpi() {} + VerilatedVpi() { m_errorInfop=NULL; } ~VerilatedVpi() {} static void cbReasonAdd(VerilatedVpioCb* vop) { if (vop->reason() == cbValueChange) { @@ -425,7 +425,7 @@ public: vl_fatal(error_info_p->file, error_info_p->line, "", error_info_p->message); return; } - vl_fatal(error_info_p->file, error_info_p->line, "", "vpi_unsupported called without error info set"); + vl_fatal(__FILE__, __LINE__, "", "vpi_unsupported called without error info set"); } static const char* strFromVpiVal(PLI_INT32 vpiVal); static const char* strFromVpiObjType(PLI_INT32 vpiVal); @@ -875,7 +875,7 @@ void vpi_get_value(vpiHandle object, p_vpi_value value_p) { val &= (1<(val)]; } outStr[i]=0; // NULL terminate return; @@ -1097,7 +1097,7 @@ vpiHandle vpi_put_value(vpiHandle object, p_vpi_value value_p, } else if (value_p->format == vpiDecStrVal) { char remainder[16]; unsigned long val; - int success = sscanf(value_p->value.str, "%lu%15s", &val, remainder); + int success = sscanf(value_p->value.str, "%30lu%15s", &val, remainder); if (success < 1) { _VL_VPI_ERROR(__FILE__, __LINE__, "%s: Parsing failed for '%s' as value %s for %s", VL_FUNC, value_p->value.str, VerilatedVpiError::strFromVpiVal(value_p->format), vop->fullname()); diff --git a/src/V3Assert.cpp b/src/V3Assert.cpp index 10318770b..0c8eff7e5 100644 --- a/src/V3Assert.cpp +++ b/src/V3Assert.cpp @@ -62,6 +62,7 @@ private: nodep->displayType(AstDisplayType::DT_WRITE); nodep->fmtp()->text(assertDisplayMessage(nodep, prefix, nodep->fmtp()->text())); AstNode* timesp = nodep->fmtp()->exprsp(); if (timesp) timesp->unlinkFrBack(); + // cppcheck-suppress nullPointer timesp = timesp->addNext(new AstTime(nodep->fileline())); nodep->fmtp()->exprsp(timesp); if (!nodep->fmtp()->scopeNamep() && nodep->fmtp()->formatScopeTracking()) { diff --git a/src/V3Ast.cpp b/src/V3Ast.cpp index 62ecb936c..d0f1a3110 100644 --- a/src/V3Ast.cpp +++ b/src/V3Ast.cpp @@ -764,6 +764,7 @@ void AstNode::iterateAndNext(AstNVisitor& v, AstNUser* vup) { while (nodep) { AstNode* niterp = nodep; // This address may get stomped via m_iterpp if the node is edited ASTNODE_PREFETCH(nodep->m_nextp); + // cppcheck-suppress nullPointer niterp->m_iterpp = &niterp; niterp->accept(v, vup); // accept may do a replaceNode and change niterp on us... diff --git a/src/V3Ast.h b/src/V3Ast.h index 6171e2f01..fc7095c5d 100644 --- a/src/V3Ast.h +++ b/src/V3Ast.h @@ -47,6 +47,7 @@ public: // enum en {...}; // const char* ascii() const {...}; enum en m_e; + // cppcheck-suppress uninitVar // responsiblity of each subclass inline AstType () {} inline AstType (en _e) : m_e(_e) {} explicit inline AstType (int _e) : m_e(static_cast(_e)) {} @@ -782,7 +783,7 @@ protected: RelinkWhatEn m_chg; AstNode** m_iterpp; public: - AstNRelinker() { m_backp=NULL; m_chg=RELINK_BAD; m_iterpp=NULL;} + AstNRelinker() { m_oldp=NULL; m_backp=NULL; m_chg=RELINK_BAD; m_iterpp=NULL;} void relink(AstNode* newp); AstNode* oldp() const { return m_oldp; } void dump(ostream& str=cout) const; @@ -1582,7 +1583,9 @@ private: AstNodeDType* m_refDTypep; // Elements of this type (after widthing) AstNode* rangenp() const { return op2p(); } // op2 = Array(s) of variable public: - AstNodeArrayDType(FileLine* fl) : AstNodeDType(fl) {} + AstNodeArrayDType(FileLine* fl) : AstNodeDType(fl) { + m_refDTypep = NULL; + } ASTNODE_BASE_FUNCS(NodeArrayDType) virtual void dump(ostream& str); virtual void dumpSmall(ostream& str); diff --git a/src/V3Begin.cpp b/src/V3Begin.cpp index 889f03744..c239352f7 100644 --- a/src/V3Begin.cpp +++ b/src/V3Begin.cpp @@ -153,7 +153,7 @@ private: AstNode* addsp = NULL; if (AstNode* stmtsp = nodep->stmtsp()) { stmtsp->unlinkFrBackWithNext(); - addsp = addsp->addNextNull(stmtsp); + if (addsp) { addsp = addsp->addNextNull(stmtsp); } else { addsp = stmtsp; } } if (addsp) { nodep->replaceWith(addsp); diff --git a/src/V3Const.cpp b/src/V3Const.cpp index f26b498b9..b0299ba56 100644 --- a/src/V3Const.cpp +++ b/src/V3Const.cpp @@ -1404,6 +1404,7 @@ private: for (AstNodeSenItem* nextp, * senp = nodep->sensesp()->castNodeSenItem(); senp; senp=nextp) { nextp=senp->nextp()->castNodeSenItem(); + // cppcheck-suppress unassignedVariable // cppcheck bug SenItemCmp cmp; if (nextp && !cmp(senp, nextp)) { // Something's out of order, sort it diff --git a/src/V3Error.h b/src/V3Error.h index 0e0a4b19f..692f9881f 100644 --- a/src/V3Error.h +++ b/src/V3Error.h @@ -294,7 +294,7 @@ protected: int nameToNumber(const string& filename); const string numberToName(int filenameno) const { return m_names[filenameno]; } const V3LangCode numberToLang(int filenameno) const { return m_languages[filenameno]; } - void numberToLang(int filenameno, const V3LangCode l) { m_languages[filenameno] = l; } + void numberToLang(int filenameno, const V3LangCode& l) { m_languages[filenameno] = l; } void clear() { m_namemap.clear(); m_names.clear(); m_languages.clear(); } void fileNameNumMapDumpXml(ostream& os); static const string filenameLetters(int fileno); diff --git a/src/V3LinkDot.cpp b/src/V3LinkDot.cpp index 480ac0fbb..a30fb78e8 100644 --- a/src/V3LinkDot.cpp +++ b/src/V3LinkDot.cpp @@ -661,7 +661,7 @@ private: // Find under either a task or the module's vars VSymEnt* foundp = m_curSymp->findIdFallback(nodep->name()); if (!foundp && m_modSymp && nodep->name() == m_modSymp->nodep()->name()) foundp = m_modSymp; // Conflicts with modname? - AstVar* findvarp = foundp->nodep()->castVar(); + AstVar* findvarp = foundp ? foundp->nodep()->castVar() : NULL; bool ins=false; if (!foundp) { ins=true; @@ -730,7 +730,7 @@ private: // Find under either a task or the module's vars VSymEnt* foundp = m_curSymp->findIdFallback(nodep->name()); if (!foundp && m_modSymp && nodep->name() == m_modSymp->nodep()->name()) foundp = m_modSymp; // Conflicts with modname? - AstEnumItem* findvarp = foundp->nodep()->castEnumItem(); + AstEnumItem* findvarp = foundp ? foundp->nodep()->castEnumItem() : NULL; bool ins=false; if (!foundp) { ins=true; @@ -1503,7 +1503,7 @@ private: VSymEnt* foundp = NULL; AstNodeFTask* taskp = NULL; foundp = m_statep->findSymPrefixed(dotSymp, nodep->name(), baddot); - taskp = foundp->nodep()->castNodeFTask(); // Maybe NULL + taskp = foundp ? foundp->nodep()->castNodeFTask() : NULL; // Maybe NULL if (taskp) { nodep->taskp(taskp); nodep->packagep(foundp->packagep()); diff --git a/src/V3List.h b/src/V3List.h index fdedb6301..67447259d 100644 --- a/src/V3List.h +++ b/src/V3List.h @@ -79,7 +79,7 @@ public: void pushBack (V3List& listr, T newp) { // "this" must be a element inside of *newp // cppcheck-suppress thisSubtraction - size_t offset = (vluint8_t*)(this) - (vluint8_t*)(newp); + size_t offset = (size_t)(vluint8_t*)(this) - (size_t)(vluint8_t*)(newp); m_nextp = NULL; if (!listr.m_headp) listr.m_headp = newp; m_prevp = listr.m_tailp; @@ -89,7 +89,7 @@ public: void pushFront (V3List& listr, T newp) { // "this" must be a element inside of *newp // cppcheck-suppress thisSubtraction - size_t offset = (vluint8_t*)(this) - (vluint8_t*)(newp); + size_t offset = (size_t)(vluint8_t*)(this) - (size_t)(vluint8_t*)(newp); m_nextp = listr.m_headp; if (m_nextp) baseToListEnt(m_nextp,offset)->m_prevp = newp; listr.m_headp = newp; @@ -100,7 +100,7 @@ public: void unlink (V3List& listr, T oldp) { // "this" must be a element inside of *oldp // cppcheck-suppress thisSubtraction - size_t offset = (vluint8_t*)(this) - (vluint8_t*)(oldp); + size_t offset = (size_t)(vluint8_t*)(this) - (size_t)(vluint8_t*)(oldp); if (m_nextp) baseToListEnt(m_nextp,offset)->m_prevp = m_prevp; else listr.m_tailp = m_prevp; if (m_prevp) baseToListEnt(m_prevp,offset)->m_nextp = m_nextp; diff --git a/src/V3Options.cpp b/src/V3Options.cpp index 15c4ddf17..6710f1c5e 100644 --- a/src/V3Options.cpp +++ b/src/V3Options.cpp @@ -77,7 +77,7 @@ struct V3OptionsImp { } } } - void addLangExt(const string &langext, const V3LangCode lc) { + void addLangExt(const string& langext, const V3LangCode& lc) { // New language extension replaces any pre-existing one. (void)m_langExts.erase(langext); m_langExts[langext] = lc; @@ -98,7 +98,7 @@ void V3Options::addIncDirUser(const string& incdir) { void V3Options::addIncDirFallback(const string& incdir) { m_impp->addIncDirFallback(incdir); } -void V3Options::addLangExt(const string &langext, const V3LangCode lc) { +void V3Options::addLangExt(const string& langext, const V3LangCode& lc) { m_impp->addLangExt(langext, lc); } void V3Options::addLibExtV(const string& libext) { @@ -1117,7 +1117,7 @@ string V3Options::parseFileArg(const string& optdir, const string& relfilename) //! Utility to see if we have a language extension argument and if so add it. bool V3Options::parseLangExt (const char* swp, //!< argument text const char* langswp, //!< option to match - const V3LangCode lc) { //!< language code + const V3LangCode& lc) { //!< language code int len = strlen(langswp); if (!strncmp(swp, langswp, len)) { addLangExt(swp + len, lc); diff --git a/src/V3Options.h b/src/V3Options.h index 4bdb15b82..2f1a262c9 100644 --- a/src/V3Options.h +++ b/src/V3Options.h @@ -150,7 +150,7 @@ class V3Options { void addFuture(const string& flag); void addIncDirUser(const string& incdir); // User requested void addIncDirFallback(const string& incdir); // Low priority if not found otherwise - void addLangExt(const string &langext, const V3LangCode lc); + void addLangExt(const string& langext, const V3LangCode& lc); void addLibExtV(const string& libext); void optimize(int level); void showVersion(bool verbose); @@ -158,7 +158,7 @@ class V3Options { bool onoff(const char* sw, const char* arg, bool& flag); bool suffixed(const char* sw, const char* arg); string parseFileArg(const string& optdir, const string& relfilename); - bool parseLangExt(const char* swp, const char* langswp, const V3LangCode lc); + bool parseLangExt(const char* swp, const char* langswp, const V3LangCode& lc); string filePathCheckOneDir(const string& modname, const string& dirname); static string getenvStr(const string& envvar, const string& defaultValue); diff --git a/src/V3Param.cpp b/src/V3Param.cpp index 3b2924b1c..06765333e 100644 --- a/src/V3Param.cpp +++ b/src/V3Param.cpp @@ -94,8 +94,8 @@ private: if (varp->isGParam()) { char ch = varp->name()[0]; ch = toupper(ch); if (ch<'A' || ch>'Z') ch='Z'; - varp->user4(usedLetter[ch]*256 + ch); - usedLetter[ch]++; + varp->user4(usedLetter[static_cast(ch)]*256 + ch); + usedLetter[static_cast(ch)]++; } } } diff --git a/src/V3SymTable.h b/src/V3SymTable.h index 25855b2dc..15a64e3f0 100644 --- a/src/V3SymTable.h +++ b/src/V3SymTable.h @@ -225,10 +225,10 @@ public: VSymMap doneSyms; os<<"SymEnt Dump:\n"; m_symRootp->dumpIterate(os, doneSyms, indent, 9999, "$root"); - bool first = false; + bool first = true; for (SymStack::iterator it = m_symsp.begin(); it != m_symsp.end(); ++it) { if (doneSyms.find(*it) == doneSyms.end()) { - if (!first++) os<<"%%Warning: SymEnt Orphans:\n"; + if (first) { first=false; os<<"%%Warning: SymEnt Orphans:\n"; } (*it)->dumpIterate(os, doneSyms, indent, 9999, "Orphan"); } } diff --git a/src/V3Tristate.cpp b/src/V3Tristate.cpp index 1cc22fb49..51854d07b 100644 --- a/src/V3Tristate.cpp +++ b/src/V3Tristate.cpp @@ -508,7 +508,7 @@ class TristateVisitor : public TristateBaseVisitor { continue; } - m_statTriSigs++; + ++m_statTriSigs; m_tgraph.didProcess(invarp); UINFO(8, " TRISTATE EXPANDING:" << invarp << endl); diff --git a/src/V3Width.cpp b/src/V3Width.cpp index 1f1ba4428..9c000a3f1 100644 --- a/src/V3Width.cpp +++ b/src/V3Width.cpp @@ -837,8 +837,8 @@ private: bool didchk = false; bool implicitParam = nodep->isParam() && bdtypep && bdtypep->implicit(); if (implicitParam) { - int width=0; if (nodep->valuep()) { + int width=0; nodep->valuep()->iterateAndNext(*this,WidthVP(width,0,PRELIM).p()); UINFO(9,"implicitParamPRELIMIV "<valuep()<