avoid overlong strings in Xft measures and in editors

svn: r1540
This commit is contained in:
Matthew Flatt 2005-12-06 19:49:12 +00:00
parent d4321d7a4e
commit 44bc3084ec
2 changed files with 35 additions and 14 deletions

View File

@ -1577,7 +1577,7 @@ void wxMediaEdit::_Insert(wxSnip *isnip, long strlen, wxchar *str, wxList *snips
break; break;
} }
} else { } else {
int sp; int sp, cnt;
addlen = strlen; addlen = strlen;
@ -1677,6 +1677,7 @@ void wxMediaEdit::_Insert(wxSnip *isnip, long strlen, wxchar *str, wxList *snips
snipStartPos = start; snipStartPos = start;
str = snip->buffer; str = snip->buffer;
sp = s + snip->dtext; sp = s + snip->dtext;
cnt = 0;
for (i = 0; i < addlen; i++) { for (i = 0; i < addlen; i++) {
if (str[sp] == '\r') if (str[sp] == '\r')
str[sp] = '\n'; str[sp] = '\n';
@ -1766,16 +1767,19 @@ void wxMediaEdit::_Insert(wxSnip *isnip, long strlen, wxchar *str, wxList *snips
snipStartPos = i + start + 1; snipStartPos = i + start + 1;
str = snip->buffer; str = snip->buffer;
sp = snip->dtext; sp = snip->dtext;
} else cnt = 0;
} else if (cnt > MAX_COUNT_FOR_SNIP) {
/* Divide up snip because it's too large: */
MakeSnipset(i + start, i + start);
snip = (wxTextSnip *)FindSnip(i + start, +1);
snipStartPos = i + start;
str = snip->buffer;
sp = snip->dtext + 1;
cnt = 1;
} else {
sp++; sp++;
} cnt++;
}
/* Divide up snip if it's too large: */
while (snip->count > MAX_COUNT_FOR_SNIP) {
long next = snipStartPos + MAX_COUNT_FOR_SNIP - 10;
MakeSnipset(snipStartPos, next);
snip = (wxTextSnip *)FindSnip(next, +1);
snipStartPos = next;
} }
firstLine = lineRoot->First(); firstLine = lineRoot->First();

View File

@ -2216,6 +2216,10 @@ static unsigned int *convert_to_drawable_format(const char *s, int ds, long *_ul
#endif #endif
static unsigned int cvt_buf[WX_CVT_BUF_SIZE]; static unsigned int cvt_buf[WX_CVT_BUF_SIZE];
/* Xft measurements use a `short'. Avoid string lengths that are
likely to overflow it. */
#define MAX_TEXT_LENGTH_FOR_MEASURE 100
void wxWindowDC::DrawText(char *orig_text, double x, double y, void wxWindowDC::DrawText(char *orig_text, double x, double y,
Bool combine, Bool isUnicode, int dt, Bool combine, Bool isUnicode, int dt,
double angle) double angle)
@ -2352,6 +2356,12 @@ void wxWindowDC::DrawText(char *orig_text, double x, double y,
try_sub = 1; try_sub = 1;
while(textlen) { while(textlen) {
int nowlen;
nowlen = textlen;
if (nowlen > MAX_TEXT_LENGTH_FOR_MEASURE) {
nowlen = MAX_TEXT_LENGTH_FOR_MEASURE;
}
if (angle != 0.0) if (angle != 0.0)
no_rotate = (wxFontStruct*)current_font->GetInternalAAFont(e_scale_x, e_scale_y, 0.0); no_rotate = (wxFontStruct*)current_font->GetInternalAAFont(e_scale_x, e_scale_y, 0.0);
else else
@ -2381,7 +2391,7 @@ void wxWindowDC::DrawText(char *orig_text, double x, double y,
/* Get a longer range that won't need a substitution */ /* Get a longer range that won't need a substitution */
if (this_time == xfontinfo) { if (this_time == xfontinfo) {
while (partlen < textlen) { while (partlen < nowlen) {
cval = text[dt + partlen]; cval = text[dt + partlen];
if (((this_time != xfontinfo) if (((this_time != xfontinfo)
&& XftGlyphExists(DPY, xfontinfo, cval)) && XftGlyphExists(DPY, xfontinfo, cval))
@ -2391,7 +2401,7 @@ void wxWindowDC::DrawText(char *orig_text, double x, double y,
} }
} }
} else { } else {
partlen = textlen; partlen = nowlen;
this_time = xfontinfo; this_time = xfontinfo;
this_time_no_rotate = no_rotate; this_time_no_rotate = no_rotate;
} }
@ -2532,10 +2542,17 @@ void wxGetTextExtent(Display *dpy, double scale_x, double scale_y,
w = 0; w = 0;
while (textlen) { while (textlen) {
int nowlen;
nowlen = textlen;
if (nowlen > MAX_TEXT_LENGTH_FOR_MEASURE) {
nowlen = MAX_TEXT_LENGTH_FOR_MEASURE;
}
if (try_sub) { if (try_sub) {
int index = 1, cval; int index = 1, cval;
partlen = 1; partlen = 1;
this_time = xfontinfo; this_time = xfontinfo;
while (1) { while (1) {
cval = s[dt]; cval = s[dt];
if (!XftGlyphExists(dpy, this_time, cval)) { if (!XftGlyphExists(dpy, this_time, cval)) {
@ -2550,7 +2567,7 @@ void wxGetTextExtent(Display *dpy, double scale_x, double scale_y,
/* Get a longer range that won't need a substitution */ /* Get a longer range that won't need a substitution */
if (this_time == xfontinfo) { if (this_time == xfontinfo) {
while (partlen < textlen) { while (partlen < nowlen) {
cval = s[dt + partlen]; cval = s[dt + partlen];
if (((this_time != xfontinfo) if (((this_time != xfontinfo)
&& XftGlyphExists(dpy, xfontinfo, cval)) && XftGlyphExists(dpy, xfontinfo, cval))
@ -2560,7 +2577,7 @@ void wxGetTextExtent(Display *dpy, double scale_x, double scale_y,
} }
} }
} else { } else {
partlen = textlen; partlen = nowlen;
this_time = xfontinfo; this_time = xfontinfo;
} }