From 48ced3ea8071b3141216482e2821e10250910947 Mon Sep 17 00:00:00 2001 From: Dimitri van Heesch Date: Tue, 18 Aug 2015 21:07:17 +0200 Subject: Fixed various issues found by PVS-Studio. --- qtools/qcstring.h | 2 +- qtools/qfile_win32.cpp | 2 +- qtools/qstring.cpp | 6 ++++-- src/classdef.cpp | 1 - src/context.cpp | 8 ++++---- src/docparser.cpp | 15 +++------------ src/docsets.cpp | 4 ---- src/doxygen.cpp | 7 +++++-- src/htmldocvisitor.cpp | 4 ++-- src/index.cpp | 4 ++-- src/layout.cpp | 2 +- src/membergroup.cpp | 2 +- src/outputgen.cpp | 5 ----- src/template.cpp | 15 ++++++--------- src/translator_tw.h | 13 ++++++------- src/util.cpp | 4 ++-- src/vhdldocgen.cpp | 2 -- src/vhdljjparser.cpp | 5 ++++- 18 files changed, 42 insertions(+), 59 deletions(-) diff --git a/qtools/qcstring.h b/qtools/qcstring.h index 4f15b18..abf30b3 100644 --- a/qtools/qcstring.h +++ b/qtools/qcstring.h @@ -149,7 +149,7 @@ public: /** creates a string with room for size characters * @param[in] size the number of character to allocate (including the 0-terminator) */ - QCString( int size ) : m_rep(size) + explicit QCString( int size ) : m_rep(size) { } diff --git a/qtools/qfile_win32.cpp b/qtools/qfile_win32.cpp index 80ad628..a4ab013 100644 --- a/qtools/qfile_win32.cpp +++ b/qtools/qfile_win32.cpp @@ -264,7 +264,7 @@ bool QFile::open( int m ) } else { length = (int)st.st_size; ioIndex = (flags() & IO_Append) == 0 ? 0 : length; - if ( (flags() & !IO_Truncate) && length == 0 && isReadable() ) { + if ( !(flags()&IO_Truncate) && length == 0 && isReadable() ) { // try if you can read from it (if you can, it's a sequential // device; e.g. a file in the /proc filesystem) int c = getch(); diff --git a/qtools/qstring.cpp b/qtools/qstring.cpp index 458fd53..d831cb1 100644 --- a/qtools/qstring.cpp +++ b/qtools/qstring.cpp @@ -11957,7 +11957,8 @@ QString QString::visual(int index, int len) QChar* QString::asciiToUnicode( const QByteArray& ba, uint* len ) { if ( ba.isNull() ) { - *len = 0; + if ( len ) + *len = 0; return 0; } int l = 0; @@ -11976,7 +11977,8 @@ QChar* QString::asciiToUnicode( const QByteArray& ba, uint* len ) static QChar* internalAsciiToUnicode( const QByteArray& ba, uint* len ) { if ( ba.isNull() ) { - *len = 0; + if ( len ) + *len = 0; return 0; } int l = 0; diff --git a/src/classdef.cpp b/src/classdef.cpp index 95428d6..1584094 100644 --- a/src/classdef.cpp +++ b/src/classdef.cpp @@ -1960,7 +1960,6 @@ void ClassDef::writeDocumentationContents(OutputList &ol,const QCString & /*page QCString pageType = " "; pageType += compoundTypeString(); - toupper(pageType.at(1)); Doxygen::indexList->addIndexItem(this,0); diff --git a/src/context.cpp b/src/context.cpp index f76c49b..e7c14d5 100644 --- a/src/context.cpp +++ b/src/context.cpp @@ -1709,7 +1709,7 @@ class ClassContext::Private : public DefinitionContext MemberList *ml = m_classDef->getMemberList(type); if (ml) { - list.reset(MemberListInfoContext::alloc(m_classDef,relPathAsString(),ml,title,detailed)); + list.reset(MemberListInfoContext::alloc(m_classDef,relPathAsString(),ml,title,"")); } } if (list) @@ -2312,7 +2312,7 @@ class NamespaceContext::Private : public DefinitionContextgetMemberList(type); if (ml) { - list.reset(MemberListInfoContext::alloc(m_namespaceDef,relPathAsString(),ml,title,detailed)); + list.reset(MemberListInfoContext::alloc(m_namespaceDef,relPathAsString(),ml,title,"")); } } if (list) @@ -2672,7 +2672,7 @@ class FileContext::Private : public DefinitionContext MemberList *ml = m_fileDef->getMemberList(type); if (ml) { - list.reset(MemberListInfoContext::alloc(m_fileDef,relPathAsString(),ml,title,detailed)); + list.reset(MemberListInfoContext::alloc(m_fileDef,relPathAsString(),ml,title,"")); } } if (list) @@ -4453,7 +4453,7 @@ class ModuleContext::Private : public DefinitionContext MemberList *ml = m_groupDef->getMemberList(type); if (ml) { - list.reset(MemberListInfoContext::alloc(m_groupDef,relPathAsString(),ml,title,detailed)); + list.reset(MemberListInfoContext::alloc(m_groupDef,relPathAsString(),ml,title,"")); } } if (list) diff --git a/src/docparser.cpp b/src/docparser.cpp index d1362f0..cb65564 100644 --- a/src/docparser.cpp +++ b/src/docparser.cpp @@ -511,18 +511,9 @@ static void checkUndocumentedParams() errMsg+=" parameter '"+argName+"'"; } } - if (g_memberDef->inheritsDocsFrom()) - { - warn_doc_error(g_memberDef->getDefFileName(), - g_memberDef->getDefLine(), - substitute(errMsg,"%","%%")); - } - else - { - warn_doc_error(g_memberDef->getDefFileName(), - g_memberDef->getDefLine(), - substitute(errMsg,"%","%%")); - } + warn_doc_error(g_memberDef->getDefFileName(), + g_memberDef->getDefLine(), + substitute(errMsg,"%","%%")); } } } diff --git a/src/docsets.cpp b/src/docsets.cpp index cde317d..9772d4e 100644 --- a/src/docsets.cpp +++ b/src/docsets.cpp @@ -468,10 +468,6 @@ void DocSets::addIndexItem(Definition *context,MemberDef *md, if (ii) { decl=ii->includeName; - if (decl.isEmpty()) - { - decl=ii->local; - } } } else if (nd) diff --git a/src/doxygen.cpp b/src/doxygen.cpp index 918cf82..4ff533d 100644 --- a/src/doxygen.cpp +++ b/src/doxygen.cpp @@ -2074,7 +2074,10 @@ static void findUsingDeclarations(EntryNav *rootNav) else { Debug::print(Debug::Classes,0," Found used class %s in scope=%s\n", - qPrint(usingCd->name()),nd?qPrint(nd->name()):qPrint(fd->name())); + qPrint(usingCd->name()), + nd?qPrint(nd->name()): + fd?qPrint(fd->name()): + ""); } if (nd) @@ -6120,7 +6123,7 @@ static void findMember(EntryNav *rootNav, // stripTemplateSpecifiersFromScope(scopeName,FALSE).data()); ClassDef *tcd=findClassDefinition(fd,nd,scopeName); - if (tcd==0 && stripAnonymousNamespaceScope(cd->name())==scopeName) + if (tcd==0 && cd && stripAnonymousNamespaceScope(cd->name())==scopeName) { // don't be fooled by anonymous scopes tcd=cd; diff --git a/src/htmldocvisitor.cpp b/src/htmldocvisitor.cpp index 54dca32..296a957 100644 --- a/src/htmldocvisitor.cpp +++ b/src/htmldocvisitor.cpp @@ -1037,7 +1037,7 @@ void HtmlDocVisitor::visitPre(DocPara *p) void HtmlDocVisitor::visitPost(DocPara *p) { bool needsTag = FALSE; - if (p && p->parent()) + if (p->parent()) { switch (p->parent()->kind()) { @@ -1067,7 +1067,7 @@ void HtmlDocVisitor::visitPost(DocPara *p) // the paragraph (
    ,
    ,) then that will already have ended the // paragraph and we don't need to do it here int nodeIndex = p->children().count()-1; - if (p && nodeIndex>=0) + if (nodeIndex>=0) { while (nodeIndex>=0 && p->children().at(nodeIndex)->kind()==DocNode::Kind_WhiteSpace) { diff --git a/src/index.cpp b/src/index.cpp index e7ba8e7..06d2185 100644 --- a/src/index.cpp +++ b/src/index.cpp @@ -3787,7 +3787,7 @@ static void writeIndex(OutputList &ol) { title = theTranslator->trMainPage(); } - else + else if (Doxygen::mainPage) { title = filterTitle(Doxygen::mainPage->title()); } @@ -4086,7 +4086,7 @@ static void writeIndexHierarchyEntries(OutputList &ol,const QListtitle().data(),lne->kind()); - bool addToIndex=lne==0 || lne->visible(); + bool addToIndex=lne->visible(); bool needsClosing=FALSE; if (!indexWritten.at(index)) { diff --git a/src/layout.cpp b/src/layout.cpp index 75cb6b3..01d5d18 100644 --- a/src/layout.cpp +++ b/src/layout.cpp @@ -888,7 +888,7 @@ class LayoutParser : public QXmlDefaultHandler // no MainPage node... add one as the first item of the root node... new LayoutNavEntry(m_rootNav,LayoutNavEntry::MainPage, TRUE, /*Config_getBool("GENERATE_TREEVIEW") ? "main" :*/ "index", - theTranslator->trMainPage(),TRUE); + theTranslator->trMainPage(),"",TRUE); } } diff --git a/src/membergroup.cpp b/src/membergroup.cpp index 4bf7721..08f951c 100644 --- a/src/membergroup.cpp +++ b/src/membergroup.cpp @@ -76,7 +76,7 @@ void MemberGroup::insertMember(MemberDef *md) // md,md->name().data()); MemberDef *firstMd = memberList->getFirst(); - if (inSameSection && memberList->count()>0 && + if (inSameSection && firstMd && firstMd->getSectionList(m_parent)!=md->getSectionList(m_parent)) { inSameSection=FALSE; diff --git a/src/outputgen.cpp b/src/outputgen.cpp index 31f682e..53d2d7f 100644 --- a/src/outputgen.cpp +++ b/src/outputgen.cpp @@ -44,11 +44,6 @@ void OutputGenerator::startPlainFile(const char *name) //printf("startPlainFile(%s)\n",name); fileName=dir+"/"+name; file = new QFile(fileName); - if (!file) - { - err("Could not create file object for %s\n",fileName.data()); - exit(1); - } if (!file->open(IO_WriteOnly)) { err("Could not open file %s for writing\n",fileName.data()); diff --git a/src/template.cpp b/src/template.cpp index 4250f08..5102978 100644 --- a/src/template.cpp +++ b/src/template.cpp @@ -1978,16 +1978,13 @@ class ExpressionParser TRACE(("{parseLiteral(%s)\n",m_curToken.id.data())); ExprAst *expr = new ExprAstLiteral(m_curToken.id); getNextToken(); - if (expr) + while (m_curToken.type==ExprToken::Operator && + m_curToken.op==Operator::Filter) { - while (m_curToken.type==ExprToken::Operator && - m_curToken.op==Operator::Filter) - { - getNextToken(); - ExprAstFilter *filter = parseFilter(); - if (!filter) break; - expr = new ExprAstFilterAppl(expr,filter); - } + getNextToken(); + ExprAstFilter *filter = parseFilter(); + if (!filter) break; + expr = new ExprAstFilterAppl(expr,filter); } TRACE(("}parseLiteral()\n")); return expr; diff --git a/src/translator_tw.h b/src/translator_tw.h index e61ab5c..31aeede 100644 --- a/src/translator_tw.h +++ b/src/translator_tw.h @@ -749,8 +749,7 @@ class TranslatorChinesetraditional : public Translator /*! This is put at the bottom of a class documentation page and is * followed by a list of files that were used to generate the page. */ - virtual QCString trGeneratedFromFiles(ClassDef::CompoundType compType, - bool single) + virtual QCString trGeneratedFromFiles(ClassDef::CompoundType compType,bool) { // here s is one of " Class", " Struct" or " Union" // single is true implies a single file QCString result=(QCString)"此"; @@ -766,7 +765,7 @@ class TranslatorChinesetraditional : public Translator default: break; } result+=" 文件是由下列檔案中產生"; - if (single) result+=":"; else result+=":"; + result+=":"; return result; } @@ -1948,21 +1947,21 @@ class TranslatorChinesetraditional : public Translator return result; } /** UNO IDL service page */ - virtual QCString trServiceGeneratedFromFiles(bool single) + virtual QCString trServiceGeneratedFromFiles(bool) { // single is true implies a single file QCString result=(QCString)"本服務的文件由以下的檔案" "所產生"; - if (single) result+=":"; else result+=":"; + result+=":"; return result; } /** UNO IDL singleton page */ - virtual QCString trSingletonGeneratedFromFiles(bool single) + virtual QCString trSingletonGeneratedFromFiles(bool) { // single is true implies a single file QCString result=(QCString)"本singleton的文件由下面的檔案" "所產生"; - if (single) result+=":"; else result+=":"; + result+=":"; return result; } diff --git a/src/util.cpp b/src/util.cpp index db6a19c..0467953 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -4291,7 +4291,7 @@ bool getDefs(const QCString &scName, bool found=FALSE; MemberListIterator mmli(*mn); MemberDef *mmd; - for (mmli.toFirst();((mmd=mmli.current()) && !found);++mmli) + for (mmli.toFirst();(mmd=mmli.current());++mmli) { MemberDef *tmd = mmd->getEnumScope(); //printf("try member %s tmd=%s\n",mmd->name().data(),tmd?tmd->name().data():""); @@ -8353,7 +8353,7 @@ void convertProtectionLevel( if (extractPrivate) { *outListType1=MemberListType_pubSlots; - *outListType1=MemberListType_proSlots; + *outListType2=MemberListType_proSlots; } else { diff --git a/src/vhdldocgen.cpp b/src/vhdldocgen.cpp index 029d0bd..3ea9b18 100644 --- a/src/vhdldocgen.cpp +++ b/src/vhdldocgen.cpp @@ -967,7 +967,6 @@ QCString VhdlDocGen::getClassTitle(const ClassDef *cd) { QCString pageTitle; if (cd==0) return ""; - pageTitle+=cd->displayName(); pageTitle=VhdlDocGen::getClassName(cd); int ii=cd->protection(); pageTitle+=" "; @@ -2163,7 +2162,6 @@ void VhdlDocGen::writeVHDLDeclaration(MemberDef* mdef,OutputList &ol, { if (VhdlDocGen::isConfig(mdef) || VhdlDocGen::isCompInst(mdef)) { - nn=mdef->getOutputFileBase(); nn=ltype; } else diff --git a/src/vhdljjparser.cpp b/src/vhdljjparser.cpp index ea43341..acef592 100644 --- a/src/vhdljjparser.cpp +++ b/src/vhdljjparser.cpp @@ -407,7 +407,10 @@ void VhdlParser::addCompInst(const char *n, const char* instName, const char* co current->type=instName; // foo:instname e.g proto or work. proto(ttt) current->exception=genLabels.lower(); // |arch|label1:label2... current->name=n; // foo - current->args=lastCompound->name; // architecture name + if (lastCompound) + { + current->args=lastCompound->name; // architecture name + } current->includeName=comp; // component/enity/configuration int u=genLabels.find("|",1); if (u>0) -- cgit v0.12