Skip to content

Commit 6221f43

Browse files
committed
Fixed a number of coverity warnings
1 parent 71f6cd6 commit 6221f43

File tree

3 files changed

+22
-23
lines changed

3 files changed

+22
-23
lines changed

src/markdown.cpp

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2738,7 +2738,7 @@ size_t Markdown::Private::writeBlockQuote(std::string_view data)
27382738
else if (j>0 && data[j-1]=='>') indent=j+1;
27392739
j++;
27402740
}
2741-
if (j>0 && data[j-1]=='>' &&
2741+
if (indent>0 && j>0 && data[j-1]=='>' &&
27422742
!(j==size || data[j]=='\n')) // disqualify last > if not followed by space
27432743
{
27442744
indent--;
@@ -2847,17 +2847,16 @@ bool skipOverFileAndLineCommands(std::string_view data,size_t indent,size_t &off
28472847
}
28482848
i++;
28492849
}
2850-
if (!found)
2850+
if (found)
28512851
{
2852-
return offset; // not found
2852+
i+=9;
2853+
location=data.substr(locStart,i-locStart);
2854+
location+='\n';
2855+
while (indent>0 && i<size && data[i]==' ') i++,indent--;
2856+
if (i<size && data[i]=='\n') i++;
2857+
offset = i;
2858+
return true;
28532859
}
2854-
i+=9;
2855-
location=data.substr(locStart,i-locStart);
2856-
location+='\n';
2857-
while (indent>0 && i<size && data[i]==' ') i++,indent--;
2858-
if (i<size && data[i]=='\n') i++;
2859-
offset = i;
2860-
return true;
28612860
}
28622861
return false;
28632862
}

src/pre.l

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2756,7 +2756,7 @@ static bool replaceFunctionMacro(yyscan_t yyscanner,const QCString &expr,QCStrin
27562756
{
27572757
inString=TRUE; // entering a literal string
27582758
}
2759-
else if (inString && d.at(k)=='\"' && (d.at(k-1)!='\\' || d.at(k-2)=='\\'))
2759+
else if (k>2 && inString && d.at(k)=='\"' && (d.at(k-1)!='\\' || d.at(k-2)=='\\'))
27602760
{
27612761
inString=FALSE; // leaving a literal string
27622762
}

src/util.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,7 @@ QCString removeRedundantWhiteSpace(const QCString &s)
611611
for (;i<l;i++)
612612
{
613613
char c=src[i];
614-
char nc=i<l-1 ? src[i+1] : ' ';
614+
char nc=i+1<l ? src[i+1] : ' ';
615615

616616
auto searchForKeyword = [&](const char *kw,size_t &matchLen,size_t totalLen)
617617
{
@@ -665,7 +665,7 @@ QCString removeRedundantWhiteSpace(const QCString &s)
665665
break;
666666
case '<': // current char is a <
667667
*dst++=c;
668-
if (i<l-1 &&
668+
if (i+1<l &&
669669
(isId(nc)) && // next char is an id char
670670
(osp<8) // string in front is not "operator"
671671
)
@@ -682,17 +682,17 @@ QCString removeRedundantWhiteSpace(const QCString &s)
682682
*dst++=' '; // add extra space in front
683683
}
684684
*dst++=c;
685-
if (i<l-1 && (nc=='-' || nc=='&')) // '>-' -> '> -'
685+
if (i+1<l && (nc=='-' || nc=='&')) // '>-' -> '> -'
686686
{
687687
*dst++=' '; // add extra space after
688688
}
689689
break;
690690
case ',': // current char is a ,
691691
*dst++=c;
692692
if (i>0 && !isspace(static_cast<uint8_t>(pc)) &&
693-
((i<l-1 && (isId(nc) || nc=='[')) || // the [ is for attributes (see bug702170)
694-
(i<l-2 && nc=='$' && isId(src[i+2])) || // for PHP: ',$name' -> ', $name'
695-
(i<l-3 && nc=='&' && src[i+2]=='$' && isId(src[i+3])) // for PHP: ',&$name' -> ', &$name'
693+
((i+1<l && (isId(nc) || nc=='[')) || // the [ is for attributes (see bug702170)
694+
(i+2<l && nc=='$' && isId(src[i+2])) || // for PHP: ',$name' -> ', $name'
695+
(i+3<l && nc=='&' && src[i+2]=='$' && isId(src[i+3])) // for PHP: ',&$name' -> ', &$name'
696696
)
697697
)
698698
{
@@ -702,14 +702,14 @@ QCString removeRedundantWhiteSpace(const QCString &s)
702702
case '^': // CLI 'Type^name' -> 'Type^ name'
703703
case '%': // CLI 'Type%name' -> 'Type% name'
704704
*dst++=c;
705-
if (cliSupport && i<l-1 && (isId(nc) || nc=='-'))
705+
if (cliSupport && i+1<l && (isId(nc) || nc=='-'))
706706
{
707707
*dst++=' '; // add extra space after
708708
}
709709
break;
710710
case ')': // current char is a ) -> ')name' -> ') name'
711711
*dst++=c;
712-
if (i<l-1 && (isId(nc) || nc=='-'))
712+
if (i+1<l && (isId(nc) || nc=='-'))
713713
{
714714
*dst++=' '; // add extra space after
715715
}
@@ -746,7 +746,7 @@ QCString removeRedundantWhiteSpace(const QCString &s)
746746
// else fallthrough
747747
case '@': // '@name' -> ' @name'
748748
case '\'': // ''name' -> '' name'
749-
if (i>0 && i<l-1 && pc!='=' && pc!=':' && !isspace(static_cast<uint8_t>(pc)) &&
749+
if (i>0 && i+1<l && pc!='=' && pc!=':' && !isspace(static_cast<uint8_t>(pc)) &&
750750
isId(nc) && osp<8) // ")id" -> ") id"
751751
{
752752
*dst++=' ';
@@ -797,7 +797,7 @@ QCString removeRedundantWhiteSpace(const QCString &s)
797797
auto correctKeywordAllowedInsideScope = [&](char cc,size_t &matchLen,size_t totalLen) {
798798
if (c==cc && matchLen==totalLen)
799799
{
800-
if ((i<l-2 && src[i+1] == ':' && src[i+2] == ':') || // keyword::
800+
if ((i+2<l && src[i+1] == ':' && src[i+2] == ':') || // keyword::
801801
((i>matchLen && src[i-matchLen] == ':' && src[i-matchLen-1] == ':')) // ::keyword
802802
) matchLen = 0;
803803
};
@@ -808,7 +808,7 @@ QCString removeRedundantWhiteSpace(const QCString &s)
808808

809809
auto correctKeywordNotPartOfScope = [&](char cc,size_t &matchLen,size_t totalLen)
810810
{
811-
if (c==cc && matchLen==totalLen && i<l-1 && // found matching keyword
811+
if (c==cc && matchLen==totalLen && i+1<l && // found matching keyword
812812
!(isId(nc) || nc==')' || nc==',' || qisspace(nc))
813813
) // prevent keyword ::A from being converted to keyword::A
814814
{
@@ -883,7 +883,7 @@ bool rightScopeMatch(const QCString &scope, const QCString &name)
883883
size_t nl=name.length();
884884
return (name==scope || // equal
885885
(scope.right(nl)==name && // substring
886-
sl-nl>1 && scope.at(sl-nl-1)==':' && scope.at(sl-nl-2)==':' // scope
886+
sl>1+nl && scope.at(sl-nl-1)==':' && scope.at(sl-nl-2)==':' // scope
887887
)
888888
);
889889
}

0 commit comments

Comments
 (0)