From cabf972164496b55e3ca06cf2ca7e9db357075aa Mon Sep 17 00:00:00 2001 From: nyamatongwe Date: Sun, 21 Mar 2004 08:53:02 +0000 Subject: 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. --- gtk/PlatGTK.cxx | 18 +++++++++++++++--- 1 file 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(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(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; -- cgit v1.2.3