author | erik <erik> | 2007-01-24 19:54:07 (UTC) |
---|---|---|
committer | erik <erik> | 2007-01-24 19:54:07 (UTC) |
commit | 89e81059e832ff77c2f0ac8b9db12f80eafa03fc (patch) (side-by-side diff) | |
tree | 99a130fc643d2aeefdecab452f644e7b61a5f50e /noncore/apps/tinykate/libkate/document/katedocument.cpp | |
parent | 035bbc5bf689839c8d8e7be37f347b0dd900fccf (diff) | |
download | opie-89e81059e832ff77c2f0ac8b9db12f80eafa03fc.zip opie-89e81059e832ff77c2f0ac8b9db12f80eafa03fc.tar.gz opie-89e81059e832ff77c2f0ac8b9db12f80eafa03fc.tar.bz2 |
Each file in this commit has an instance where a pointer is checked at
one point in the code and then not checked in another point in the code.
If it needed to be checked once, it needs to be checked the other time. If not
the application could segfault.
Diffstat (limited to 'noncore/apps/tinykate/libkate/document/katedocument.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/apps/tinykate/libkate/document/katedocument.cpp | 123 |
1 files changed, 62 insertions, 61 deletions
diff --git a/noncore/apps/tinykate/libkate/document/katedocument.cpp b/noncore/apps/tinykate/libkate/document/katedocument.cpp index b82a86a..692fd46 100644 --- a/noncore/apps/tinykate/libkate/document/katedocument.cpp +++ b/noncore/apps/tinykate/libkate/document/katedocument.cpp @@ -2014,9 +2014,9 @@ void KateDocument::paintTextLine(QPainter &paint, int line, int y, int xStart, i int len; const QChar *s; int z, x; QChar ch; - Attribute *a = 0L; + Attribute *attrptr = 0L; int attr, nextAttr; int xs; int xc, zc; @@ -2039,18 +2039,18 @@ void KateDocument::paintTextLine(QPainter &paint, int line, int y, int xStart, i ch = s[z];//textLine->getChar(z); if (ch == '\t') { x += m_tabWidth - (x % m_tabWidth); } else { - a = &m_attribs[textLine->getAttr(z)]; - - if (a->bold && a->italic) - x += myFontMetricsBI.width(ch); - else if (a->bold) - x += myFontMetricsBold.width(ch); - else if (a->italic) - x += myFontMetricsItalic.width(ch); - else - x += myFontMetrics.width(ch); + attrptr = &m_attribs[textLine->getAttr(z)]; + + if (attrptr->bold && attrptr->italic) + x += myFontMetricsBI.width(ch); + else if (attrptr->bold) + x += myFontMetricsBold.width(ch); + else if (attrptr->italic) + x += myFontMetricsItalic.width(ch); + else + x += myFontMetrics.width(ch); } z++; } while (x <= xStart); @@ -2078,15 +2078,15 @@ void KateDocument::paintTextLine(QPainter &paint, int line, int y, int xStart, i if (ch == '\t') x += m_tabWidth - (x % m_tabWidth); else { - a = &m_attribs[textLine->getAttr(z)]; + attrptr = &m_attribs[textLine->getAttr(z)]; - if (a->bold && a->italic) + if (attrptr->bold && attrptr->italic) x += myFontMetricsBI.width(ch); - else if (a->bold) + else if (attrptr->bold) x += myFontMetricsBold.width(ch); - else if (a->italic) + else if (attrptr->italic) x += myFontMetricsItalic.width(ch); else x += myFontMetrics.width(ch); } @@ -2113,40 +2113,38 @@ void KateDocument::paintTextLine(QPainter &paint, int line, int y, int xStart, i QConstString str((QChar *) &s[zc], z - zc /*+1*/); QString s = str.string(); paint.drawText(x - xStart, y, s); - if (a->bold && a->italic) - x += myFontMetricsBI.width(s); - else if (a->bold) - x += myFontMetricsBold.width(s); - else if (a->italic) - x += myFontMetricsItalic.width(s); - else - x += myFontMetrics.width(s); + if (attrptr && attrptr->bold && attrptr->italic) + x += myFontMetricsBI.width(s); + else if (attrptr && attrptr->bold) + x += myFontMetricsBold.width(s); + else if (attrptr && attrptr->italic) + x += myFontMetricsItalic.width(s); + else + x += myFontMetrics.width(s); } zc = z +1; if (showTabs) { nextAttr = textLine->getRawAttr(z); if (nextAttr != attr) { attr = nextAttr; - a = &m_attribs[attr & taAttrMask]; - - if (attr & taSelected) paint.setPen(a->selCol); - else paint.setPen(a->col); - - if (a->bold && a->italic) - paint.setFont(myFontBI); - else if (a->bold) - paint.setFont(myFontBold); - else if (a->italic) - paint.setFont(myFontItalic); - else - paint.setFont(myFont); + attrptr = &m_attribs[attr & taAttrMask]; + + if (attr & taSelected) paint.setPen(attrptr->selCol); + else paint.setPen(attrptr->col); + + if (attrptr->bold && attrptr->italic) + paint.setFont(myFontBI); + else if (attrptr->bold) + paint.setFont(myFontBold); + else if (attrptr->italic) + paint.setFont(myFontItalic); + else + paint.setFont(myFont); } -// paint.drawLine(x - xStart, y -2, x - xStart, y); -// paint.drawLine(x - xStart, y, x - xStart + 2, y); paint.drawPoint(x - xStart, y); paint.drawPoint(x - xStart +1, y); paint.drawPoint(x - xStart, y -1); } @@ -2158,32 +2156,32 @@ void KateDocument::paintTextLine(QPainter &paint, int line, int y, int xStart, i QConstString str((QChar *) &s[zc], z - zc /*+1*/); QString s = str.string(); paint.drawText(x - xStart, y, s); - if (a->bold && a->italic) - x += myFontMetricsBI.width(s); - else if (a->bold) - x += myFontMetricsBold.width(s); - else if (a->italic) - x += myFontMetricsItalic.width(s); - else - x += myFontMetrics.width(s); + if (attrptr->bold && attrptr->italic) + x += myFontMetricsBI.width(s); + else if (attrptr->bold) + x += myFontMetricsBold.width(s); + else if (attrptr->italic) + x += myFontMetricsItalic.width(s); + else + x += myFontMetrics.width(s); zc = z; } attr = nextAttr; - a = &m_attribs[attr & taAttrMask]; - - if (attr & taSelected) paint.setPen(a->selCol); - else paint.setPen(a->col); - - if (a->bold && a->italic) - paint.setFont(myFontBI); - else if (a->bold) - paint.setFont(myFontBold); - else if (a->italic) - paint.setFont(myFontItalic); - else - paint.setFont(myFont); + attrptr = &m_attribs[attr & taAttrMask]; + + if (attr & taSelected) paint.setPen(attrptr->selCol); + else paint.setPen(attrptr->col); + + if (attrptr->bold && attrptr->italic) + paint.setFont(myFontBI); + else if (attrptr->bold) + paint.setFont(myFontBold); + else if (attrptr->italic) + paint.setFont(myFontItalic); + else + paint.setFont(myFont); } } z++; } @@ -2226,9 +2224,11 @@ bool KateDocument::doSearch(SConfig &sc, const QString &searchFor) { if (tlen > bufLen) { delete [] t; bufLen = (tlen + 255) & (~255); t = new QChar[bufLen]; - } + } else if (!t) + t = new QChar[bufLen]; + memcpy(t, textLine->getText(), tlen*sizeof(QChar)); if (sc.flags & KateView::sfSelected) { pos = 0; do { @@ -2287,9 +2287,10 @@ bool KateDocument::doSearch(SConfig &sc, const QString &searchFor) { if (tlen > bufLen) { delete [] t; bufLen = (tlen + 255) & (~255); t = new QChar[bufLen]; - } + } else if (!t) + t = new QChar[bufLen]; memcpy(t, textLine->getText(), tlen*sizeof(QChar)); if (sc.flags & KateView::sfSelected) { pos = 0; do { |