Skip to content

Commit

Permalink
Fixed several Coverity warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
Dimitri van Heesch committed Nov 15, 2014
1 parent e986e00 commit 9b7e4ff
Show file tree
Hide file tree
Showing 22 changed files with 189 additions and 148 deletions.
1 change: 1 addition & 0 deletions qtools/qfile_unix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,7 @@ int QFile::writeBlock( const char *p, uint len )
return -1;
}
#endif
if (p==0) return 0;
int nwritten; // number of bytes written
if ( isRaw() ) // raw file
nwritten = (int)WRITE( fd, p, len );
Expand Down
19 changes: 10 additions & 9 deletions src/condparser.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,25 @@ class CondParser
{
// public functions
public:
CondParser() : m_e(0), m_tokenType(NOTHING) {}
bool parse(const char *fileName,int lineNr,const char *expr);

// enumerations
private:
enum TOKENTYPE
enum TOKENTYPE
{
NOTHING = -1,
DELIMITER,
VARIABLE,
NOTHING = -1,
DELIMITER,
VARIABLE,
UNKNOWN
};
enum OPERATOR_ID
enum OPERATOR_ID
{
UNKNOWN_OP = -1,
AND = 1,
OR,
UNKNOWN_OP = -1,
AND = 1,
OR,
NOT
};
};

// data
private:
Expand Down
6 changes: 4 additions & 2 deletions src/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5760,7 +5760,8 @@ class ClassTreeContext::Private : public PropertyMapper
SharedPtr<NestingContext> m_classTree;
struct Cachable
{
Cachable() : maxDepthComputed(FALSE), preferredDepthComputed(FALSE) {}
Cachable() : maxDepth(0), maxDepthComputed(FALSE),
preferredDepth(0), preferredDepthComputed(FALSE) {}
int maxDepth;
bool maxDepthComputed;
int preferredDepth;
Expand Down Expand Up @@ -6168,7 +6169,8 @@ class FileTreeContext::Private : public PropertyMapper
SharedPtr<NestingContext> m_dirFileTree;
struct Cachable
{
Cachable() : maxDepthComputed(FALSE), preferredDepthComputed(FALSE) {}
Cachable() : maxDepth(0), maxDepthComputed(FALSE),
preferredDepth(0), preferredDepthComputed(FALSE) {}
int maxDepth;
bool maxDepthComputed;
int preferredDepth;
Expand Down
16 changes: 8 additions & 8 deletions src/definition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ class DefinitionImpl

SectionDict *sectionDict; // dictionary of all sections, not accessible

MemberSDict *sourceRefByDict;
MemberSDict *sourceRefsDict;
QList<ListItemInfo> *xrefListItems;
GroupList *partOfGroups;
MemberSDict *sourceRefByDict;
MemberSDict *sourceRefsDict;
QList<ListItemInfo> *xrefListItems;
GroupList *partOfGroups;

DocInfo *details; // not exported
DocInfo *inbodyDocs; // not exported
Expand Down Expand Up @@ -89,11 +89,11 @@ class DefinitionImpl
QCString id; // clang unique id
};

DefinitionImpl::DefinitionImpl()
: sectionDict(0), sourceRefByDict(0), sourceRefsDict(0),
DefinitionImpl::DefinitionImpl()
: sectionDict(0), sourceRefByDict(0), sourceRefsDict(0),
xrefListItems(0), partOfGroups(0),
details(0), inbodyDocs(0), brief(0), body(0),
outerScope(0)
details(0), inbodyDocs(0), brief(0), body(0), hidden(FALSE), isArtificial(FALSE),
outerScope(0), lang(SrcLangExt_Unknown)
{
}

Expand Down
2 changes: 1 addition & 1 deletion src/dirdef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

static int g_dirCount=0;

DirDef::DirDef(const char *path) : Definition(path,1,1,path)
DirDef::DirDef(const char *path) : Definition(path,1,1,path), visited(FALSE)
{
bool fullPathNames = Config_getBool("FULL_PATH_NAMES");
// get display name (stipping the paths mentioned in STRIP_FROM_PATH)
Expand Down
12 changes: 5 additions & 7 deletions src/docbookgen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,22 +178,22 @@ class TextGeneratorDocbookImpl : public TextGeneratorIntf
class DocbookCodeGenerator : public CodeOutputInterface
{
public:
DocbookCodeGenerator(FTextStream &t) : m_t(t), m_lineNumber(-1),
DocbookCodeGenerator(FTextStream &t) : m_t(t), m_lineNumber(-1), m_col(0),
m_insideCodeLine(FALSE), m_insideSpecialHL(FALSE) {}
virtual ~DocbookCodeGenerator() {}

void codify(const char *text)
{
Docbook_DB(("(codify \"%s\")\n",text));
writeDocbookCodeString(m_t,text,col);
writeDocbookCodeString(m_t,text,m_col);
}
void writeCodeLink(const char *ref,const char *file,
const char *anchor,const char *name,
const char *tooltip)
{
Docbook_DB(("(writeCodeLink)\n"));
writeDocbookLink(m_t,ref,file,anchor,name,tooltip);
col+=strlen(name);
m_col+=strlen(name);
}
void writeTooltip(const char *, const DocLinkInfo &, const char *,
const char *, const SourceLinkInfo &, const SourceLinkInfo &
Expand All @@ -217,7 +217,7 @@ class DocbookCodeGenerator : public CodeOutputInterface
}
}
m_insideCodeLine=TRUE;
col=0;
m_col=0;
}
void endCodeLine()
{
Expand Down Expand Up @@ -255,7 +255,6 @@ class DocbookCodeGenerator : public CodeOutputInterface
{
m_refId=compId;
if (anchorId) m_refId+=(QCString)"_1"+anchorId;
m_isMemberRef = anchorId!=0;
if (extRef) m_external=extRef;
}
}
Expand All @@ -275,8 +274,7 @@ class DocbookCodeGenerator : public CodeOutputInterface
QCString m_refId;
QCString m_external;
int m_lineNumber;
bool m_isMemberRef;
int col;
int m_col;
bool m_insideCodeLine;
bool m_insideSpecialHL;
};
Expand Down
23 changes: 11 additions & 12 deletions src/docparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2089,6 +2089,11 @@ DocFormula::DocFormula(DocNode *parent,int id) :
m_name.sprintf("form_%d",m_id);
m_text = formula->getFormulaText();
}
else // wrong \form#<n> command
{
warn_doc_error(g_fileName,doctokenizerYYlineno,"Wrong formula id %d",id);
m_id = -1;
}
}

//---------------------------------------------------------------------------
Expand Down Expand Up @@ -2366,7 +2371,7 @@ DocRef::DocRef(DocNode *parent,const QCString &target,const QCString &context) :
// compound->definitionType());
return;
}
else if (compound->definitionType()==Definition::TypeFile &&
else if (compound && compound->definitionType()==Definition::TypeFile &&
((FileDef*)compound)->generateSourceFile()
) // undocumented file that has source code we can link to
{
Expand Down Expand Up @@ -2485,9 +2490,8 @@ DocCite::DocCite(DocNode *parent,const QCString &target,const QCString &) //cont

DocLink::DocLink(DocNode *parent,const QCString &target)
{
m_parent = parent;
Definition *compound;
//PageInfo *page;
m_parent = parent;
Definition *compound = 0;
QCString anchor;
m_refText = target;
m_relPath = g_relPath;
Expand All @@ -2504,7 +2508,7 @@ DocLink::DocLink(DocNode *parent,const QCString &target)
m_file = compound->getOutputFileBase();
m_ref = compound->getReference();
}
else if (compound->definitionType()==Definition::TypeFile &&
else if (compound && compound->definitionType()==Definition::TypeFile &&
((FileDef*)compound)->generateSourceFile()
) // undocumented file that has source code we can link to
{
Expand Down Expand Up @@ -3308,7 +3312,6 @@ int DocIndexEntry::parse()
break;
}
}
if (tok!=0) retval=tok;
doctokenizerYYsetStatePara();
m_entry = m_entry.stripWhiteSpace();
endindexentry:
Expand Down Expand Up @@ -6786,17 +6789,13 @@ int DocSection::parse()
}
else if ((m_level<=1+Doxygen::subpageNestingLevel && retval==RetVal_Subsubsection) ||
(m_level<=2+Doxygen::subpageNestingLevel && retval==RetVal_Paragraph)
)
)
{
int level;
if (retval==RetVal_Subsection) level=2;
else if (retval==RetVal_Subsubsection) level=3;
else level=4;
int level = (retval==RetVal_Subsubsection) ? 3 : 4;
warn_doc_error(g_fileName,doctokenizerYYlineno,"Unexpected %s "
"command found inside %s!",
sectionLevelToName[level],sectionLevelToName[m_level]);
retval=0; // stop parsing

}
else
{
Expand Down
44 changes: 25 additions & 19 deletions src/filename.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,12 @@ void FileName::generateDiskNames()
{
// skip references
for (it.toFirst();(fd=it.current()) && fd->isReference();++it) { }
// name if unique, so diskname is simply the name
//printf("!!!!!!!! Unique disk name=%s for fd=%s\n",name.data(),fd->diskname.data());
fd->m_diskName=name;
if (fd)
{
// name if unique, so diskname is simply the name
//printf("!!!!!!!! Unique disk name=%s for fd=%s\n",name.data(),fd->diskname.data());
fd->m_diskName=name;
}
}
else if (count>1) // multiple occurrences of the same file name
{
Expand All @@ -57,28 +60,31 @@ void FileName::generateDiskNames()
while (!found) // search for the common prefix of all paths
{
for (it.toFirst();(fd=it.current()) && fd->isReference();++it) { }
char c=fd->m_path.at(i);
if (c=='/') j=i; // remember last position of dirname
++it;
while ((fd=it.current()) && !found)
if (fd)
{
if (!fd->isReference())
char c=fd->m_path.at(i);
if (c=='/') j=i; // remember last position of dirname
++it;
while ((fd=it.current()) && !found)
{
//printf("i=%d j=%d fd->path=`%s' fd->name=`%s'\n",i,j,fd->path.left(i).data(),fd->name().data());
if (i==(int)fd->m_path.length())
if (!fd->isReference())
{
//warning("Input file %s found multiple times!\n"
// " The generated documentation for this file may not be correct!\n",fd->absFilePath().data());
found=TRUE;
}
else if (fd->m_path[i]!=c)
{
found=TRUE;
//printf("i=%d j=%d fd->path=`%s' fd->name=`%s'\n",i,j,fd->path.left(i).data(),fd->name().data());
if (i==(int)fd->m_path.length())
{
//warning("Input file %s found multiple times!\n"
// " The generated documentation for this file may not be correct!\n",fd->absFilePath().data());
found=TRUE;
}
else if (fd->m_path[i]!=c)
{
found=TRUE;
}
}
++it;
}
++it;
i++;
}
i++;
}
for (it.toFirst();(fd=it.current());++it)
{
Expand Down
28 changes: 17 additions & 11 deletions src/htmlgen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -737,17 +737,24 @@ void HtmlGenerator::init()
if (f.open(IO_WriteOnly))
{
const Resource *res = mgr.get("dynsections.js");
FTextStream t(&f);
t << (const char *)res->data;
if (Config_getBool("SOURCE_BROWSER") && Config_getBool("SOURCE_TOOLTIPS"))
if (res)
{
FTextStream t(&f);
t << (const char *)res->data;
if (Config_getBool("SOURCE_BROWSER") && Config_getBool("SOURCE_TOOLTIPS"))
{
t << endl <<
"$(document).ready(function() {\n"
" $('.code,.codeRef').each(function() {\n"
" $(this).data('powertip',$('#'+$(this).attr('href').replace(/.*\\//,'').replace(/[^a-z_A-Z0-9]/g,'_')).html());\n"
" $(this).powerTip({ placement: 's', smartPlacement: true, mouseOnToPopup: true });\n"
" });\n"
"});\n";
}
}
else
{
t << endl <<
"$(document).ready(function() {\n"
" $('.code,.codeRef').each(function() {\n"
" $(this).data('powertip',$('#'+$(this).attr('href').replace(/.*\\//,'').replace(/[^a-z_A-Z0-9]/g,'_')).html());\n"
" $(this).powerTip({ placement: 's', smartPlacement: true, mouseOnToPopup: true });\n"
" });\n"
"});\n";
err("Resource dynsections.js not compiled in");
}
}
}
Expand Down Expand Up @@ -896,7 +903,6 @@ void HtmlGenerator::writeSearchInfo(FTextStream &t,const QCString &relPath)
t << " onmouseover=\"return searchBox.OnSearchSelectShow()\"\n";
t << " onmouseout=\"return searchBox.OnSearchSelectHide()\"\n";
t << " onkeydown=\"return searchBox.OnSearchSelectKey(event)\">\n";
writeSearchCategories(t);
t << "</div>\n";
t << "\n";
t << "<!-- iframe showing the search results (closed by default) -->\n";
Expand Down
2 changes: 1 addition & 1 deletion src/markdown.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2375,7 +2375,7 @@ void MarkdownFileParser::parseInput(const char *fileName,
Doxygen::markdownSupport = TRUE;

bool needsEntry = FALSE;
Protection prot;
Protection prot=Public;
while (parseCommentBlock(
this,
current,
Expand Down
4 changes: 2 additions & 2 deletions src/memberdef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,7 @@ MemberDef::MemberDef(const char *df,int dl,int dc,
const char *t,const char *na,const char *a,const char *e,
Protection p,Specifier v,bool s,Relationship r,MemberType mt,
const ArgumentList *tal,const ArgumentList *al
) : Definition(df,dl,dc,removeRedundantWhiteSpace(na))
) : Definition(df,dl,dc,removeRedundantWhiteSpace(na)), visited(FALSE)
{
//printf("MemberDef::MemberDef(%s)\n",na);
m_impl = new MemberDefImpl;
Expand All @@ -748,7 +748,7 @@ MemberDef::MemberDef(const char *df,int dl,int dc,
m_isDestructorCached = 0;
}

MemberDef::MemberDef(const MemberDef &md) : Definition(md)
MemberDef::MemberDef(const MemberDef &md) : Definition(md), visited(FALSE)
{
m_impl = new MemberDefImpl;
m_isLinkableCached = 0;
Expand Down
21 changes: 20 additions & 1 deletion src/memberlist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,35 @@
#include "config.h"
#include "docparser.h"

MemberList::MemberList()
MemberList::MemberList() : m_listType(MemberListType_pubMethods)
{
memberGroupList=0;
m_varCnt=0;
m_funcCnt=0;
m_enumCnt=0;
m_enumValCnt=0;
m_typeCnt=0;
m_protoCnt=0;
m_defCnt=0;
m_friendCnt=0;
m_numDecMembers=-1; // special value indicating that value needs to be computed
m_numDocMembers=-1; // special value indicating that value needs to be computed
m_inGroup=FALSE;
m_inFile=FALSE;
m_needsSorting=FALSE;
}

MemberList::MemberList(MemberListType lt) : m_listType(lt)
{
memberGroupList=0;
m_varCnt=0;
m_funcCnt=0;
m_enumCnt=0;
m_enumValCnt=0;
m_typeCnt=0;
m_protoCnt=0;
m_defCnt=0;
m_friendCnt=0;
m_numDecMembers=-1; // special value indicating that value needs to be computed
m_numDocMembers=-1; // special value indicating that value needs to be computed
m_inGroup=FALSE;
Expand Down
Loading

0 comments on commit 9b7e4ff

Please sign in to comment.