Skip to content

Commit bdaa81e

Browse files
committed
Fixed potential invalid memory access when reading code fragments
1 parent 93b11f6 commit bdaa81e

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

src/definition.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -843,6 +843,10 @@ bool readCodeFragment(const QCString &fileName,bool isMacro,
843843
{
844844
found=TRUE;
845845
}
846+
else if (c==0)
847+
{
848+
break;
849+
}
846850
}
847851
//printf(" -> readCodeFragment(%s,%d,%d) lineNr=%d\n",fileName,startLine,endLine,lineNr);
848852
if (found)
@@ -871,11 +875,12 @@ bool readCodeFragment(const QCString &fileName,bool isMacro,
871875
int size_read=0;
872876
do
873877
{
874-
// read up to maxLineLength-1 bytes, the last byte being zero
878+
// read up to blockSize-1 non-zero characters
875879
int i=0;
876-
while ((c=*p++) && i<blockSize-1)
880+
while ((c=*p) && i<blockSize-1)
877881
{
878882
lineStr[i++]=c;
883+
p++;
879884
if (c=='\n') break; // stop at end of the line
880885
}
881886
lineStr[i]=0;

0 commit comments

Comments
 (0)