aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authornyamatongwe <devnull@localhost>2004-03-21 08:53:02 +0000
committernyamatongwe <devnull@localhost>2004-03-21 08:53:02 +0000
commitc14183ccaa18b7540f4af0b044e12090f61fc6e6 (patch)
tree922105f0a60dc2b6e97c56a12673c9b235d0e154
parent019b39ae147b4cf103ef8d04760bed28e7ed1919 (diff)
downloadscintilla-mirror-c14183ccaa18b7540f4af0b044e12090f61fc6e6.tar.gz
Copy DBCS text to be drawn or measured into another buffer
so that is can be \0 terminated. Previously read beyond end of text segment. When mblen returns -1 to say byte is not part of DBCS string, convert to 1 so loop does not run over.
-rw-r--r--gtk/PlatGTK.cxx18
1 files changed, 15 insertions, 3 deletions
diff --git a/gtk/PlatGTK.cxx b/gtk/PlatGTK.cxx
index c37ff56ca..bfd5166c5 100644
--- a/gtk/PlatGTK.cxx
+++ b/gtk/PlatGTK.cxx
@@ -1169,13 +1169,18 @@ void SurfaceImpl::DrawTextBase(PRectangle rc, Font &font_, int ybase, const char
bool draw8bit = true;
if (et != singleByte) {
GdkWChar wctext[maxLengthTextRun];
+ if (len >= maxLengthTextRun)
+ len = maxLengthTextRun-1;
int wclen;
if (et == UTF8) {
wclen = UCS2FromUTF8(s, len,
reinterpret_cast<wchar_t *>(wctext), maxLengthTextRun - 1);
} else { // dbcs, so convert using current locale
+ char sMeasure[maxLengthTextRun];
+ memcpy(sMeasure, s, len);
+ sMeasure[len] = '\0';
wclen = gdk_mbstowcs(
- wctext, s, maxLengthTextRun - 1);
+ wctext, sMeasure, maxLengthTextRun - 1);
}
if (wclen > 0) {
draw8bit = false;
@@ -1326,13 +1331,18 @@ void SurfaceImpl::MeasureWidths(Font &font_, const char *s, int len, int *positi
bool measure8bit = true;
if (et != singleByte) {
GdkWChar wctext[maxLengthTextRun];
+ if (len >= maxLengthTextRun)
+ len = maxLengthTextRun-1;
int wclen;
if (et == UTF8) {
wclen = UCS2FromUTF8(s, len,
reinterpret_cast<wchar_t *>(wctext), maxLengthTextRun - 1);
} else { // dbcsMode, so convert using current locale
+ char sDraw[maxLengthTextRun];
+ memcpy(sDraw, s, len);
+ sDraw[len] = '\0';
wclen = gdk_mbstowcs(
- wctext, s, maxLengthTextRun - 1);
+ wctext, sDraw, maxLengthTextRun - 1);
}
if (wclen > 0) {
measure8bit = false;
@@ -1342,11 +1352,13 @@ void SurfaceImpl::MeasureWidths(Font &font_, const char *s, int len, int *positi
for (int iU = 0; iU < wclen; iU++) {
int width = gdk_char_width_wc(gf, wctext[iU]);
totalWidth += width;
- size_t lenChar;
+ int lenChar;
if (et == UTF8) {
lenChar = UTF8Len(s[i]);
} else {
lenChar = mblen(s+i, MB_CUR_MAX);
+ if (lenChar < 0)
+ lenChar = 1;
}
while (lenChar--) {
positions[i++] = totalWidth;