Skip to content

Commit 1af459c

Browse files
committed
Refactoring: make sure all variables are initialized
Found using clang tidy's cppcoreguidelines-init-variables check
1 parent 9d9c29a commit 1af459c

File tree

111 files changed

+981
-1204
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

111 files changed

+981
-1204
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ if (ENABLE_CLANG_TIDY)
9292
set(CMAKE_CXX_CLANG_TIDY clang-tidy;
9393
-header-filter=.;
9494
-checks=-*,cppcoreguidelines-special-member-functions
95+
#-checks=-*,cppcoreguidelines-init-variables
9596
#-checks=-*,modernize-use-nullptr
9697
#-checks=-*,modernize-use-override
9798
#-checks=-*,modernize-use-emplace

src/aliases.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -234,9 +234,9 @@ static std::string replaceAliasArguments(StringUnorderedSet &aliasesProcessed,
234234

235235
// first make a list of arguments from the comma separated argument list
236236
StringViewVector args;
237-
size_t i,l=argList.length();
237+
size_t l=argList.length();
238238
size_t p=0;
239-
for (i=0;i<l;i++)
239+
for (size_t i=0;i<l;i++)
240240
{
241241
char c = argList[i];
242242
if (!sep.empty() &&
@@ -264,7 +264,7 @@ static std::string replaceAliasArguments(StringUnorderedSet &aliasesProcessed,
264264
bool insideMarkerId = false;
265265
size_t markerStart = 0;
266266
auto isDigit = [](char c) { return c>='0' && c<='9'; };
267-
for (i=0;i<=l;i++)
267+
for (size_t i=0;i<=l;i++)
268268
{
269269
char c = i<l ? aliasValue[i] : '\0';
270270
if (insideMarkerId && !isDigit(c)) // found end of a markerId
@@ -472,12 +472,11 @@ static int countAliasArguments(std::string_view args, std::string_view sep)
472472

473473
static std::string extractAliasArgs(std::string_view args)
474474
{
475-
size_t i;
476475
int bc = 0;
477476
char prevChar = 0;
478477
if (!args.empty() && args[0]=='{') // alias has argument
479478
{
480-
for (i=0;i<args.length();i++)
479+
for (size_t i=0;i<args.length();i++)
481480
{
482481
char c = args[i];
483482
if (prevChar!='\\') // not escaped

src/cite.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ void CitationManager::insertCrossReferencesForBibFile(const QCString &bibFile)
141141
std::string lineStr;
142142
while (getline(f,lineStr))
143143
{
144-
int i;
144+
int i = -1;
145145
QCString line(lineStr);
146146
if (line.stripWhiteSpace().startsWith("@"))
147147
{
@@ -213,7 +213,7 @@ QCString CitationManager::getFormulas(const QCString &s)
213213
const size_t tmpLen = 30;
214214
char tmp[tmpLen];
215215
const char *ps=s.data();
216-
char c;
216+
char c = 0;
217217
while ((c=*ps++))
218218
{
219219
if (insideFormula)
@@ -283,7 +283,7 @@ QCString CitationManager::replaceFormulas(const QCString &s)
283283
if (s.isEmpty()) return s;
284284
QCString t;
285285
int pos=0;
286-
int i;
286+
int i = -1;
287287
while ((i=s.find(g_formulaMarker.c_str(),pos))!=-1)
288288
{
289289
t += s.mid(pos,i-pos);
@@ -397,10 +397,10 @@ void CitationManager::generatePage()
397397

398398
// 5. run bib2xhtml perl script on the generated file which will insert the
399399
// bibliography in citelist.doc
400-
int exitCode;
401400
QCString perlArgs = "\""+bib2xhtmlFile+"\" "+bibOutputFiles+" \""+ citeListFile+"\"";
402401
if (citeDebug) perlArgs+=" -d";
403-
if ((exitCode=Portable::system("perl",perlArgs)) != 0)
402+
int exitCode = Portable::system("perl",perlArgs);
403+
if (exitCode!=0)
404404
{
405405
err("Problems running bibtex. Verify that the command 'perl --version' works from the command line. Exit code: %d\n",
406406
exitCode);
@@ -461,7 +461,7 @@ void CitationManager::generatePage()
461461
CommentScanner commentScanner;
462462
int lineNr = 0;
463463
int pos = 0;
464-
Protection prot;
464+
Protection prot = Protection::Public;
465465
commentScanner.parseCommentBlock(
466466
nullptr,
467467
&current,

src/clangparser.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ std::string ClangTUParser::lookup(uint32_t line,const char *symbol)
351351

352352
auto getCurrentTokenLine = [=]() -> uint32_t
353353
{
354-
uint32_t l, c;
354+
uint32_t l=0, c=0;
355355
if (p->numTokens==0) return 1;
356356
// guard against filters that reduce the number of lines
357357
if (p->curToken>=p->numTokens) p->curToken=p->numTokens-1;
@@ -403,7 +403,7 @@ std::string ClangTUParser::lookup(uint32_t line,const char *symbol)
403403
ts = clang_getCString(tokenString);
404404
tl = ts ? strlen(ts) : 0;
405405
// skip over any spaces in the symbol
406-
char c;
406+
char c = 0;
407407
while (offset<sl && ((c=symbol[offset])==' ' || c=='\t' || c=='\r' || c=='\n'))
408408
{
409409
offset++;
@@ -574,7 +574,7 @@ void ClangTUParser::codifyLines(OutputCodeList &ol,const FileDef *fd,const char
574574
{
575575
if (fontClass) ol.startFontClass(fontClass);
576576
const char *p=text,*sp=p;
577-
char c;
577+
char c = 0;
578578
bool inlineCodeFragment = false;
579579
bool done=FALSE;
580580
while (!done)
@@ -624,7 +624,7 @@ void ClangTUParser::writeMultiLineCodeLink(OutputCodeList &ol,
624624
while (!done)
625625
{
626626
const char *sp=p;
627-
char c;
627+
char c = 0;
628628
while ((c=*p++) && c!='\n') { column++; }
629629
if (c=='\n')
630630
{
@@ -804,7 +804,7 @@ void ClangTUParser::writeSources(OutputCodeList &ol,const FileDef *fd)
804804
for (unsigned int i=0;i<p->numTokens;i++)
805805
{
806806
CXSourceLocation start = clang_getTokenLocation(p->tu, p->tokens[i]);
807-
unsigned int l, c;
807+
unsigned int l=0, c=0;
808808
clang_getSpellingLocation(start, nullptr, &l, &c, nullptr);
809809
if (l > line) column = 1;
810810
while (line<l)

src/classdef.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2771,7 +2771,7 @@ void ClassDefImpl::writeDocumentation(OutputList &ol) const
27712771
bool sliceOpt = Config_getBool(OPTIMIZE_OUTPUT_SLICE);
27722772
QCString pageTitle = title();
27732773

2774-
HighlightedItem hli;
2774+
HighlightedItem hli = HighlightedItem::None;
27752775
if (sliceOpt)
27762776
{
27772777
if (compoundType()==Interface)
@@ -2918,7 +2918,7 @@ void ClassDefImpl::writeMemberList(OutputList &ol) const
29182918
ol.pushGeneratorState();
29192919
ol.disableAllBut(OutputType::Html);
29202920

2921-
HighlightedItem hli;
2921+
HighlightedItem hli = HighlightedItem::None;
29222922
if (sliceOpt)
29232923
{
29242924
if (compoundType()==Interface)
@@ -3541,8 +3541,8 @@ void ClassDefImpl::mergeMembersFromBaseClasses(bool mergeVirtualBaseClass)
35413541

35423542
for (auto &srcMni : srcMnd)
35433543
{
3544-
MemberNameInfo *dstMni;
3545-
if ((dstMni=dstMnd.find(srcMni->memberName())))
3544+
MemberNameInfo *dstMni=dstMnd.find(srcMni->memberName());
3545+
if (dstMni)
35463546
// a member with that name is already in the class.
35473547
// the member may hide or reimplement the one in the sub class
35483548
// or there may be another path to the base class that is already
@@ -4430,7 +4430,7 @@ int ClassDefImpl::countInheritedDecMembers(MemberListType lt,
44304430
for (const auto &ibcd : m_impl->inherits)
44314431
{
44324432
ClassDefMutable *icd=toClassDefMutable(ibcd.classDef);
4433-
int lt1,lt2;
4433+
int lt1=-1,lt2=-1;
44344434
if (icd && icd->isLinkable())
44354435
{
44364436
convertProtectionLevel(lt,ibcd.prot,&lt1,&lt2);
@@ -4547,7 +4547,7 @@ void ClassDefImpl::writeInheritedMemberDeclarations(OutputList &ol,ClassDefSet &
45474547
ClassDefMutable *icd=toClassDefMutable(ibcd.classDef);
45484548
if (icd && icd->isLinkable())
45494549
{
4550-
int lt1,lt3;
4550+
int lt1=-1, lt3=-1;
45514551
convertProtectionLevel(lt,ibcd.prot,&lt1,&lt3);
45524552
if (lt2==-1 && lt3!=-1)
45534553
{

src/code.l

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -502,9 +502,8 @@ ENDQopt ("const"|"volatile"|"sealed"|"override")({BN}+("const"|"volatile"|"seale
502502
}
503503
<ReadInclude>[^\n\"\>]+/(">"|"\"") {
504504
//FileInfo *f;
505-
bool ambig;
506-
bool found=FALSE;
507-
505+
bool found = false;
506+
bool ambig = false;
508507
QCString absIncFileName = determineAbsoluteIncludeName(yyextra->absFileName,yytext);
509508
const FileDef *fd=findFileDef(Doxygen::inputNameLinkedMap,absIncFileName,ambig);
510509
//printf("looking for include %s -> %s fd=%p\n",yytext,qPrint(absPath),fd);
@@ -2691,7 +2690,7 @@ static void writeMultiLineCodeLink(yyscan_t yyscanner,OutputCodeList &ol,
26912690
while (!done)
26922691
{
26932692
const char *sp=p;
2694-
char c;
2693+
char c = 0;
26952694
while ((c=*p++) && c!='\n') { }
26962695
if (c=='\n')
26972696
{
@@ -2832,7 +2831,6 @@ static const MemberDef *setCallContextForVar(yyscan_t yyscanner,const QCString &
28322831
}
28332832
}
28342833

2835-
const MemberName *mn;
28362834
const ScopedTypeVariant *mcv = yyextra->theVarContext.findVariable(name);
28372835
if (mcv)
28382836
{
@@ -2866,7 +2864,8 @@ static const MemberDef *setCallContextForVar(yyscan_t yyscanner,const QCString &
28662864
}
28672865

28682866
// look for a global member
2869-
if ((mn=Doxygen::functionNameLinkedMap->find(name)))
2867+
const MemberName *mn = Doxygen::functionNameLinkedMap->find(name);
2868+
if (mn)
28702869
{
28712870
DBG_CTX((stderr,"global var '%s'\n",qPrint(name)));
28722871
if (mn->size()==1) // global defined only once
@@ -2908,7 +2907,7 @@ static void updateCallContextForSmartPointer(yyscan_t yyscanner)
29082907
struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
29092908
const Definition *d = yyextra->theCallContext.getScope().globalDef();
29102909
//printf("updateCallContextForSmartPointer() cd=%s\n",cd ? qPrint(d->name()) : "<none>");
2911-
const MemberDef *md;
2910+
const MemberDef *md = nullptr;
29122911
if (d && d->definitionType()==Definition::TypeClass && (md=(toClassDef(d))->isSmartPointer()))
29132912
{
29142913
const ClassDef *ncd = stripClassName(yyscanner,md->typeString(),md->getOuterScope());
@@ -3377,7 +3376,7 @@ static void generateMemberLink(yyscan_t yyscanner,
33773376
MemberName *vmn=Doxygen::memberNameLinkedMap->find(varName);
33783377
if (vmn==nullptr)
33793378
{
3380-
int vi;
3379+
int vi = 0;
33813380
QCString vn=varName;
33823381
if ((vi=vn.findRev("::"))!=-1 || (vi=vn.findRev('.'))!=-1) // explicit scope A::b(), probably static member
33833382
{
@@ -3557,7 +3556,7 @@ static int countLines(yyscan_t yyscanner)
35573556
{
35583557
struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
35593558
const char *p=yyextra->inputString;
3560-
char c;
3559+
char c = 0;
35613560
int count=1;
35623561
while ((c=*p))
35633562
{
@@ -3596,7 +3595,7 @@ static void writeObjCMethodCall(yyscan_t yyscanner,ObjCCallCtx *ctx)
35963595
{
35973596
if (ctx==nullptr) return;
35983597
struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
3599-
char c;
3598+
char c = 0;
36003599
if (!ctx->methodName.isEmpty())
36013600
{
36023601
DBG_CTX((stderr,"writeObjCMethodCall(%s) obj=%s method=%s\n",
@@ -3988,7 +3987,7 @@ static bool skipLanguageSpecificKeyword(yyscan_t yyscanner,const char *keyword)
39883987
"union", "unsigned", "using", "virtual", "wchar_t",
39893988
"xor", "xor_eq", "override", "sealed"
39903989
};
3991-
bool retval;
3990+
bool retval = false;
39923991
switch (yyextra->lang)
39933992
{
39943993
case SrcLangExt::Cpp:
@@ -3997,7 +3996,7 @@ static bool skipLanguageSpecificKeyword(yyscan_t yyscanner,const char *keyword)
39973996
case SrcLangExt::Java:
39983997
retval = (non_java_keywords.find(keyword) != non_java_keywords.end());
39993998
break;
4000-
default:
3999+
default:
40014000
retval = false;
40024001
break;
40034002
}

src/codefragment.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ void CodeFragmentManager::Private::FragmentInfo::findBlockMarkers()
6464
// find the potential snippet blocks (can also be other array like stuff in the file)
6565
const char *s=fileContents.data();
6666
int lineNr=1;
67-
char c;
67+
char c=0;
6868
const char *foundOpen=nullptr;
6969
std::unordered_map<std::string,BlockMarker> candidates;
7070
while ((c=*s))
@@ -105,7 +105,7 @@ void CodeFragmentManager::Private::FragmentInfo::findBlockMarkers()
105105
s=fileContents.data();
106106
static auto gotoLine = [](const char *startBuf, const char *startPos, int startLine, int targetLine) -> const char *
107107
{
108-
char cc;
108+
char cc=0;
109109
if (targetLine<startLine)
110110
{
111111
//printf("gotoLine(pos=%p,start=%d,target=%d) backward\n",(void*)startPos,startLine,targetLine);
@@ -133,8 +133,8 @@ void CodeFragmentManager::Private::FragmentInfo::findBlockMarkers()
133133
static auto lineIndent = [](const char *&ss) -> int
134134
{
135135
int tabSize=Config_getInt(TAB_SIZE);
136-
int col=0;
137-
char cc;
136+
int col = 0;
137+
char cc = 0;
138138
while ((cc=*ss++))
139139
{
140140
if (cc==' ') col++;
@@ -205,8 +205,8 @@ void CodeFragmentManager::Private::FragmentInfo::findBlockMarkers()
205205
// process lines until the end of the indented block
206206
while (s < ee)
207207
{
208-
int col=0;
209-
char cc;
208+
int col = 0;
209+
char cc = 0;
210210
// skip over indentation
211211
while (col < marker.indent && (cc=*s++))
212212
{
@@ -263,7 +263,7 @@ static QCString readTextFileByName(const QCString &file)
263263
}
264264

265265
// as a fallback we also look in the exampleNameDict
266-
bool ambig;
266+
bool ambig=false;
267267
FileDef *fd = findFileDef(Doxygen::exampleNameLinkedMap,file,ambig);
268268
if (fd)
269269
{

src/commentcnv.l

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1378,7 +1378,7 @@ static void replaceCommentMarker(yyscan_t yyscanner,std::string_view s)
13781378
if (s.empty()) return;
13791379
size_t p = 0;
13801380
size_t len = s.length();
1381-
char c;
1381+
char c = 0;
13821382
// copy leading blanks
13831383
while (p<len && (c=s[p]) && (c==' ' || c=='\t' || c=='\n'))
13841384
{
@@ -1421,7 +1421,7 @@ static inline int computeIndent(const char *s)
14211421
int col=0;
14221422
int tabSize=Config_getInt(TAB_SIZE);
14231423
const char *p=s;
1424-
char c;
1424+
char c = 0;
14251425
while ((c=*p++))
14261426
{
14271427
if (c==' ') col++;
@@ -1678,7 +1678,7 @@ static bool readIncludeFile(yyscan_t yyscanner,const QCString &inc,const QCStrin
16781678
return false;
16791679
}
16801680
lineNr = lineBlock(incText, blockId);
1681-
int blockPos;
1681+
int blockPos = 0;
16821682
incText = extractBlock(incText, blockId, blockPos);
16831683
fs->fileBuf.clear();
16841684
if (!incText.isEmpty())

src/commentscan.l

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3923,11 +3923,11 @@ static bool handleToc(yyscan_t yyscanner,const QCString &, const StringVector &o
39233923
for (const auto &opt_ : optList)
39243924
{
39253925
QCString opt = QCString(opt_).stripWhiteSpace().lower();
3926-
char dum;
39273926
int level = SectionType::MaxLevel;
39283927
int i = opt.find(':');
39293928
if (i>0) // found ':' but not on position 0 what would mean just a level
39303929
{
3930+
char dum=0;
39313931
if (sscanf(opt.right(opt.length() - i - 1).data(),"%d%c",&level,&dum) != 1)
39323932
{
39333933
warn(yyextra->fileName,yyextra->lineNr,"Unknown option:level specified with \\tableofcontents: '%s'", qPrint(QCString(opt_).stripWhiteSpace()));
@@ -4283,10 +4283,9 @@ static void stripTrailingWhiteSpace(QCString &s)
42834283
{
42844284
size_t len = s.length();
42854285
int i = (int)len-1;
4286-
char c;
42874286
while (i>=0)
42884287
{
4289-
c = s.at(i);
4288+
char c = s.at(i);
42904289
if (c==' ' || c=='\t' || c=='\r') // normal whitespace
42914290
{
42924291
i--;

src/condparser.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -190,19 +190,16 @@ bool CondParser::parseLevel1()
190190
*/
191191
bool CondParser::parseLevel2()
192192
{
193-
bool ans;
194193
int opId = getOperatorId(m_token);
195194
if (opId == NOT)
196195
{
197196
getToken();
198-
ans = !parseLevel3();
197+
return !parseLevel3();
199198
}
200199
else
201200
{
202-
ans = parseLevel3();
201+
return parseLevel3();
203202
}
204-
205-
return ans;
206203
}
207204

208205

0 commit comments

Comments
 (0)