Skip to content

Commit 0c57f01

Browse files
committed
Added nullptr check to catch programming errors
1 parent e19c19e commit 0c57f01

File tree

1 file changed

+35
-30
lines changed

1 file changed

+35
-30
lines changed

src/commentscan.l

Lines changed: 35 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ static bool handleILine(yyscan_t yyscanner,const QCString &, const StringVector
172172
[[maybe_unused]] static const char *stateToString(int state);
173173

174174
typedef bool (*DocCmdFunc)(yyscan_t yyscanner,const QCString &name, const StringVector &optList);
175-
typedef EntryType (*makeEntryType)();
175+
typedef EntryType (*MakeEntryType)();
176176

177177
enum class CommandSpacing
178178
{
@@ -454,7 +454,7 @@ struct commentscanYY_state
454454
OutlineParserInterface *langParser = nullptr; // the language parser that is calling us
455455
QCString inputString; // input string
456456
QCString currentCmd; // the command used
457-
makeEntryType currentMakeEntryType;
457+
MakeEntryType currentMakeEntryType = nullptr;
458458
int inputPosition = 0; // read pointer
459459
QCString fileName; // file name that is read from
460460
int lineNr = 0; // line number in the input
@@ -528,7 +528,7 @@ static void stripTrailingWhiteSpace(QCString &s);
528528

529529
static void initParser(yyscan_t yyscanner);
530530
static bool checkStructuralIndicator(yyscan_t yyscanner);
531-
[[maybe_unused]] static bool makeStructuralIndicator(yyscan_t yyscanner,EntryType t);
531+
[[maybe_unused]] static bool makeStructuralIndicator(yyscan_t yyscanner,MakeEntryType maker);
532532
static void lineCount(yyscan_t yyscanner);
533533
static void addXRefItem(yyscan_t yyscanner,
534534
const QCString &listName,const QCString &itemTitle,
@@ -1254,7 +1254,7 @@ STopt [^\n@\\]*
12541254
/* ------------ handle argument of enum command --------------- */
12551255

12561256
<EnumDocArg1>{SCOPEID} { // handle argument
1257-
makeStructuralIndicator(yyscanner,yyextra->currentMakeEntryType());
1257+
makeStructuralIndicator(yyscanner,yyextra->currentMakeEntryType);
12581258
yyextra->current->name = yytext;
12591259
BEGIN( Comment );
12601260
}
@@ -1275,7 +1275,7 @@ STopt [^\n@\\]*
12751275
/* ------------ handle argument of namespace command --------------- */
12761276

12771277
<NameSpaceDocArg1>{SCOPENAME} { // handle argument
1278-
makeStructuralIndicator(yyscanner,yyextra->currentMakeEntryType());
1278+
makeStructuralIndicator(yyscanner,yyextra->currentMakeEntryType);
12791279
lineCount(yyscanner);
12801280
yyextra->current->name = substitute(removeRedundantWhiteSpace(QCString(yytext)),QCString("."),QCString("::"));
12811281
BEGIN( Comment );
@@ -1321,7 +1321,7 @@ STopt [^\n@\\]*
13211321
/* ------------ handle argument of concept command --------------- */
13221322

13231323
<ConceptDocArg1>{SCOPEID} { // handle argument
1324-
makeStructuralIndicator(yyscanner,yyextra->currentMakeEntryType());
1324+
makeStructuralIndicator(yyscanner,yyextra->currentMakeEntryType);
13251325
yyextra->current->name = yytext;
13261326
BEGIN( Comment );
13271327
}
@@ -1342,7 +1342,7 @@ STopt [^\n@\\]*
13421342

13431343
/* ------------ handle argument of module command --------------- */
13441344
<ModuleDocArg1>{MODULE_ID} { // handle argument
1345-
makeStructuralIndicator(yyscanner,yyextra->currentMakeEntryType());
1345+
makeStructuralIndicator(yyscanner,yyextra->currentMakeEntryType);
13461346
yyextra->current->name = yytext;
13471347
BEGIN( Comment );
13481348
}
@@ -1364,13 +1364,13 @@ STopt [^\n@\\]*
13641364
/* ------ handle argument of class/struct/union command --------------- */
13651365

13661366
<ClassDocArg1>{SCOPENAME}{TMPLSPEC} {
1367-
makeStructuralIndicator(yyscanner,yyextra->currentMakeEntryType());
1367+
makeStructuralIndicator(yyscanner,yyextra->currentMakeEntryType);
13681368
lineCount(yyscanner);
13691369
yyextra->current->name = substitute(removeRedundantWhiteSpace(QCString(yytext)),".","::");
13701370
BEGIN( ClassDocArg2 );
13711371
}
13721372
<ClassDocArg1>{SCOPENAME} { // first argument
1373-
makeStructuralIndicator(yyscanner,yyextra->currentMakeEntryType());
1373+
makeStructuralIndicator(yyscanner,yyextra->currentMakeEntryType);
13741374
lineCount(yyscanner);
13751375
yyextra->current->name = substitute(QCString(yytext),".","::");
13761376
if (yyextra->current->section.isProtocolDoc())
@@ -1381,7 +1381,7 @@ STopt [^\n@\\]*
13811381
BEGIN( ClassDocArg2 );
13821382
}
13831383
<CategoryDocArg1>{SCOPENAME}{B}*"("[^\)]+")" {
1384-
makeStructuralIndicator(yyscanner,yyextra->currentMakeEntryType());
1384+
makeStructuralIndicator(yyscanner,yyextra->currentMakeEntryType);
13851385
lineCount(yyscanner);
13861386
yyextra->current->name = substitute(QCString(yytext),".","::");
13871387
BEGIN( ClassDocArg2 );
@@ -2500,7 +2500,7 @@ STopt [^\n@\\]*
25002500
}
25012501
else
25022502
{
2503-
makeStructuralIndicator(yyscanner,yyextra->currentMakeEntryType());
2503+
makeStructuralIndicator(yyscanner,yyextra->currentMakeEntryType);
25042504
yyextra->langParser->parsePrototype(yyextra->functionProto);
25052505
}
25062506
unput_string(yytext,yyleng);
@@ -2539,7 +2539,7 @@ STopt [^\n@\\]*
25392539
}
25402540
else // overload declaration
25412541
{
2542-
makeStructuralIndicator(yyscanner,EntryType::makeOverloadDoc());
2542+
makeStructuralIndicator(yyscanner,EntryType::makeOverloadDoc);
25432543
yyextra->langParser->parsePrototype(yyextra->functionProto);
25442544
}
25452545
BEGIN( Comment );
@@ -2765,7 +2765,7 @@ static bool handleEnum(yyscan_t yyscanner,const QCString &, const StringVector &
27652765
static bool handleDefGroup(yyscan_t yyscanner,const QCString &, const StringVector &)
27662766
{
27672767
struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
2768-
bool stop=makeStructuralIndicator(yyscanner,EntryType::makeGroupDoc());
2768+
bool stop=makeStructuralIndicator(yyscanner,EntryType::makeGroupDoc);
27692769
yyextra->current->groupDocType = Entry::GROUPDOC_NORMAL;
27702770
BEGIN( GroupDocArg1 );
27712771
return stop;
@@ -2774,7 +2774,7 @@ static bool handleDefGroup(yyscan_t yyscanner,const QCString &, const StringVect
27742774
static bool handleAddToGroup(yyscan_t yyscanner,const QCString &, const StringVector &)
27752775
{
27762776
struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
2777-
bool stop=makeStructuralIndicator(yyscanner,EntryType::makeGroupDoc());
2777+
bool stop=makeStructuralIndicator(yyscanner,EntryType::makeGroupDoc);
27782778
yyextra->current->groupDocType = Entry::GROUPDOC_ADD;
27792779
BEGIN( GroupDocArg1 );
27802780
return stop;
@@ -2783,7 +2783,7 @@ static bool handleAddToGroup(yyscan_t yyscanner,const QCString &, const StringVe
27832783
static bool handleWeakGroup(yyscan_t yyscanner,const QCString &, const StringVector &)
27842784
{
27852785
struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
2786-
bool stop=makeStructuralIndicator(yyscanner,EntryType::makeGroupDoc());
2786+
bool stop=makeStructuralIndicator(yyscanner,EntryType::makeGroupDoc);
27872787
yyextra->current->groupDocType = Entry::GROUPDOC_WEAK;
27882788
BEGIN( GroupDocArg1 );
27892789
return stop;
@@ -2800,7 +2800,7 @@ static bool handleNamespace(yyscan_t yyscanner,const QCString &, const StringVec
28002800
static bool handlePackage(yyscan_t yyscanner,const QCString &, const StringVector &)
28012801
{
28022802
struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
2803-
bool stop=makeStructuralIndicator(yyscanner,EntryType::makePackageDoc());
2803+
bool stop=makeStructuralIndicator(yyscanner,EntryType::makePackageDoc);
28042804
BEGIN( PackageDocArg1 );
28052805
return stop;
28062806
}
@@ -2896,15 +2896,15 @@ static bool handleIdlException(yyscan_t yyscanner,const QCString &cmd, const Str
28962896
static bool handlePage(yyscan_t yyscanner,const QCString &, const StringVector &)
28972897
{
28982898
struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
2899-
bool stop=makeStructuralIndicator(yyscanner,EntryType::makePageDoc());
2899+
bool stop=makeStructuralIndicator(yyscanner,EntryType::makePageDoc);
29002900
BEGIN( PageDocArg1 );
29012901
return stop;
29022902
}
29032903

29042904
static bool handleMainpage(yyscan_t yyscanner,const QCString &, const StringVector &)
29052905
{
29062906
struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
2907-
bool stop=makeStructuralIndicator(yyscanner,EntryType::makeMainpageDoc());
2907+
bool stop=makeStructuralIndicator(yyscanner,EntryType::makeMainpageDoc);
29082908
if (!stop)
29092909
{
29102910
yyextra->current->name = "mainpage";
@@ -2917,7 +2917,7 @@ static bool handleMainpage(yyscan_t yyscanner,const QCString &, const StringVect
29172917
static bool handleFile(yyscan_t yyscanner,const QCString &, const StringVector &)
29182918
{
29192919
struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
2920-
bool stop=makeStructuralIndicator(yyscanner,EntryType::makeFileDoc());
2920+
bool stop=makeStructuralIndicator(yyscanner,EntryType::makeFileDoc);
29212921
if (!stop)
29222922
{
29232923
yyextra->current->name = yyextra->fileName;
@@ -2947,7 +2947,7 @@ static bool handleRetval(yyscan_t yyscanner,const QCString &, const StringVector
29472947
static bool handleDir(yyscan_t yyscanner,const QCString &, const StringVector &)
29482948
{
29492949
struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
2950-
bool stop=makeStructuralIndicator(yyscanner,EntryType::makeDirDoc());
2950+
bool stop=makeStructuralIndicator(yyscanner,EntryType::makeDirDoc);
29512951
if (!stop) yyextra->current->name = yyextra->fileName;
29522952
BEGIN( FileDocArg1 );
29532953
return stop;
@@ -2956,20 +2956,20 @@ static bool handleDir(yyscan_t yyscanner,const QCString &, const StringVector &)
29562956
static bool handleExample(yyscan_t yyscanner,const QCString &cmd, const StringVector &optList)
29572957
{
29582958
struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
2959-
EntryType section = EntryType::makeExample();
2959+
MakeEntryType sectionMaker = EntryType::makeExample;
29602960
for (const auto &opt : optList)
29612961
{
29622962
if (opt=="lineno")
29632963
{
2964-
section=EntryType::makeExampleLineno();
2964+
sectionMaker=EntryType::makeExampleLineno;
29652965
}
29662966
else
29672967
{
29682968
warn(yyextra->fileName,yyextra->lineNr,
29692969
"unsupported option '%s' for command '\\%s'",opt.c_str(),qPrint(cmd));
29702970
}
29712971
}
2972-
bool stop=makeStructuralIndicator(yyscanner,section);
2972+
bool stop=makeStructuralIndicator(yyscanner,sectionMaker);
29732973
if (!stop) yyextra->current->name = yyextra->fileName;
29742974
BEGIN( FileDocArg1 );
29752975
return stop;
@@ -3005,7 +3005,7 @@ static bool handleNoop(yyscan_t yyscanner,const QCString &, const StringVector &
30053005
static bool handleName(yyscan_t yyscanner,const QCString &, const StringVector &)
30063006
{
30073007
struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
3008-
bool stop=makeStructuralIndicator(yyscanner,EntryType::makeMemberGrp());
3008+
bool stop=makeStructuralIndicator(yyscanner,EntryType::makeMemberGrp);
30093009
if (!stop)
30103010
{
30113011
yyextra->docGroup.clearHeader();
@@ -3968,22 +3968,27 @@ static bool checkStructuralIndicator(yyscan_t yyscanner)
39683968
return yyextra->current->section.isDoc();
39693969
}
39703970

3971-
static bool makeStructuralIndicator(yyscan_t yyscanner,EntryType t)
3971+
static bool makeStructuralIndicator(yyscan_t yyscanner,MakeEntryType maker)
39723972
{
39733973
struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
3974+
assert(maker!=nullptr); // detect programming error
39743975
//printf("yyextra->current->section=%x\n",yyextra->current->section);
39753976
if (yyextra->current->section.isDoc())
39763977
{
3977-
return TRUE;
3978+
return true;
39783979
}
3979-
else
3980+
else if (maker)
39803981
{
3981-
yyextra->needNewEntry = TRUE;
3982-
yyextra->current->section = t;
3982+
yyextra->needNewEntry = true;
3983+
yyextra->current->section = maker();
39833984
yyextra->current->fileName = yyextra->fileName;
39843985
yyextra->current->startLine = yyextra->lineNr;
39853986
if (yyextra->current->docLine == -1) yyextra->current->docLine = yyextra->lineNr;
3986-
return FALSE;
3987+
return false;
3988+
}
3989+
else
3990+
{
3991+
return false;
39873992
}
39883993
}
39893994

0 commit comments

Comments
 (0)