Skip to content

Commit 90ae39c

Browse files
committed
Fixed potential crash in handling empty list item.
1 parent 265b08e commit 90ae39c

File tree

3 files changed

+20
-9
lines changed

3 files changed

+20
-9
lines changed

src/doctokenizer.l

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include <ctype.h>
2828
#include <stack>
2929
#include <string>
30+
#include <cassert>
3031

3132
#include "doctokenizer.h"
3233
#include "cmdmapper.h"
@@ -115,12 +116,12 @@ bool doctokenizerYYpopContext()
115116

116117
QCString extractPartAfterNewLine(const QCString &text)
117118
{
118-
int nl1 = text.findRev('\n');
119+
int nl1 = text.find('\n');
119120
if (nl1!=-1)
120121
{
121122
return text.mid(nl1+1);
122123
}
123-
int nl2 = text.findRev("\\ilinebr");
124+
int nl2 = text.find("\\ilinebr");
124125
if (nl2!=-1)
125126
{
126127
if (text.at(nl2+8)==' ') nl2++; // skip space after \\ilinebr
@@ -499,6 +500,7 @@ RCSID "$"("Author"|"Date"|"Header"|"Id"|"Locker"|"Log"|"Name"|"RCSfile"|"Revisio
499500
lineCount(yytext,yyleng);
500501
QCString text=yytext;
501502
size_t dashPos = static_cast<size_t>(text.findRev('-'));
503+
assert(dashPos!=std::string::npos);
502504
g_token->isEnumList = text.at(dashPos+1)=='#';
503505
g_token->id = -1;
504506
g_token->indent = computeIndent(yytext,dashPos);
@@ -517,6 +519,7 @@ RCSID "$"("Author"|"Date"|"Header"|"Id"|"Locker"|"Log"|"Name"|"RCSfile"|"Revisio
517519
reg::Match match;
518520
reg::search(text,match,re);
519521
size_t listPos = match.position();
522+
assert(listPos!=std::string::npos);
520523
g_token->isEnumList = FALSE;
521524
g_token->id = -1;
522525
g_token->indent = computeIndent(yytext,listPos);
@@ -534,16 +537,19 @@ RCSID "$"("Author"|"Date"|"Header"|"Id"|"Locker"|"Log"|"Name"|"RCSfile"|"Revisio
534537
static const reg::Ex re(R"(\d+)");
535538
reg::Match match;
536539
reg::search(text,match,re);
540+
size_t markPos = match.position();
541+
assert(markPos!=std::string::npos);
537542
g_token->isEnumList = true;
538543
g_token->id = std::stoul(match.str());
539-
g_token->indent = computeIndent(yytext,match.position());
544+
g_token->indent = computeIndent(yytext,markPos);
540545
return TK_LISTITEM;
541546
}
542547
}
543548
<St_Para>{BLANK}*(\n|"\\ilinebr"){LISTITEM} { /* list item on next line */
544549
lineCount(yytext,yyleng);
545550
QCString text=extractPartAfterNewLine(yytext);
546551
size_t dashPos = static_cast<size_t>(text.findRev('-'));
552+
assert(dashPos!=std::string::npos);
547553
g_token->isEnumList = text.at(dashPos+1)=='#';
548554
g_token->id = -1;
549555
g_token->indent = computeIndent(text,dashPos);
@@ -562,6 +568,7 @@ RCSID "$"("Author"|"Date"|"Header"|"Id"|"Locker"|"Log"|"Name"|"RCSfile"|"Revisio
562568
reg::Match match;
563569
reg::search(text,match,re);
564570
size_t markPos = match.position();
571+
assert(markPos!=std::string::npos);
565572
g_token->isEnumList = FALSE;
566573
g_token->id = -1;
567574
g_token->indent = computeIndent(text.c_str(),markPos);
@@ -580,15 +587,18 @@ RCSID "$"("Author"|"Date"|"Header"|"Id"|"Locker"|"Log"|"Name"|"RCSfile"|"Revisio
580587
static const reg::Ex re(R"(\d+)");
581588
reg::Match match;
582589
reg::search(text,match,re);
590+
size_t markPos = match.position();
591+
assert(markPos!=std::string::npos);
583592
g_token->isEnumList = true;
584593
g_token->id = std::stoul(match.str());
585-
g_token->indent = computeIndent(text.c_str(),match.position());
594+
g_token->indent = computeIndent(text.c_str(),markPos);
586595
return TK_LISTITEM;
587596
}
588597
}
589598
<St_Para>^{ENDLIST} { /* end list */
590599
lineCount(yytext,yyleng);
591600
int dotPos = QCString(yytext).findRev('.');
601+
assert(dotPos!=-1);
592602
g_token->indent = computeIndent(yytext,dotPos);
593603
return TK_ENDLIST;
594604
}

src/utf8.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,16 @@
1313
*
1414
*/
1515

16+
#include <cstdint>
1617
#include <sstream>
1718

1819
#include "utf8.h"
1920
#include "caseconvert.h"
2021
#include "textstream.h"
2122

22-
int getUTF8CharNumBytes(char c)
23+
uint8_t getUTF8CharNumBytes(char c)
2324
{
24-
int num=1;
25+
uint8_t num=1;
2526
unsigned char uc = static_cast<unsigned char>(c);
2627
if (uc>=0x80u) // multibyte character
2728
{
@@ -173,8 +174,8 @@ std::string convertUTF8ToUpper(const std::string &input)
173174
const char *writeUTF8Char(TextStream &t,const char *s)
174175
{
175176
if (s==0) return 0;
176-
int len = getUTF8CharNumBytes(*s);
177-
for (int i=0;i<len;i++)
177+
uint8_t len = getUTF8CharNumBytes(*s);
178+
for (uint8_t i=0;i<len;i++)
178179
{
179180
if (s[i]==0) // detect premature end of string (due to invalid UTF8 char)
180181
{

src/utf8.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ uint32_t getUnicodeForUTF8CharAt(const std::string &input,size_t pos);
5151
/** Returns the number of bytes making up a single UTF8 character given the first byte
5252
* in the sequence.
5353
*/
54-
int getUTF8CharNumBytes(char firstByte);
54+
uint8_t getUTF8CharNumBytes(char firstByte);
5555

5656
/** Writes the UTF8 character pointed to by s to stream t and returns a pointer
5757
* to the next character.

0 commit comments

Comments
 (0)