Skip to content

Commit 0458c35

Browse files
authored
Merge pull request #57 from fiendish/master
Don't walk off the end of the string
2 parents f8bd9ae + 61bb672 commit 0458c35

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

mushview.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1916,7 +1916,7 @@ long pixel;
19161916
pixel = calculate_width (line, col, pDoc, dc) + pDoc->m_iPixelOffset + pLine->m_iPreambleOffset;
19171917

19181918
// for a UTF-8 character, bypass the whole character not just one byte
1919-
if (pDoc->m_bUTF_8)
1919+
if (pDoc->m_bUTF_8 && (col < pLine->len))
19201920
{
19211921
int c = pLine->text [col];
19221922
if (c >= 128)
@@ -1929,7 +1929,7 @@ long pixel;
19291929
col--; // columns are zero-relative
19301930
// don't stop half-way through a UTF-8 character
19311931
if (pDoc->m_bUTF_8)
1932-
while (col && (pLine->text [col] & 0xC0) == 0x80)
1932+
while ((col > 0) && (col < pLine->len) && (pLine->text [col] & 0xC0) == 0x80)
19331933
col++;
19341934

19351935
// if we are 50% through this character, take the next one, otherwise take the previous one
@@ -1943,7 +1943,7 @@ long pixel;
19431943
col--;
19441944
// don't stop half-way through a UTF-8 character
19451945
if (pDoc->m_bUTF_8)
1946-
while (col && (pLine->text [col] & 0xC0) == 0x80)
1946+
while ((col > 0) && (pLine->text [col] & 0xC0) == 0x80)
19471947
col--;
19481948
}
19491949
}

0 commit comments

Comments
 (0)