summaryrefslogtreecommitdiffstats
path: root/src/svg/qsvghandler.cpp
diff options
context:
space:
mode:
authorKim Motoyoshi Kalland <kim.kalland@nokia.com>2009-09-07 09:16:39 (GMT)
committerKim Motoyoshi Kalland <kim.kalland@nokia.com>2009-09-07 09:27:43 (GMT)
commit4d044d5947bd7b49b93146097d934ccdce3746c2 (patch)
treeda7b83e66b24452a007054374f1c9b75c307315d /src/svg/qsvghandler.cpp
parent84bd6d5e10506d179e12f842659d98f7f9ef7e62 (diff)
downloadQt-4d044d5947bd7b49b93146097d934ccdce3746c2.zip
Qt-4d044d5947bd7b49b93146097d934ccdce3746c2.tar.gz
Qt-4d044d5947bd7b49b93146097d934ccdce3746c2.tar.bz2
Fixed resolving colors of the form "rgb(r,g,b)" in SVGs.
The bug was introduced by 13bcc92274d52fa6df2d636c78cf6ea457d670aa. Instead of comparing only the beginning of a string with "rgb(", a full string compare was used. I also added some error handling to avoid crashing on noncompliant SVG files. Reviewed-by: Trond
Diffstat (limited to 'src/svg/qsvghandler.cpp')
-rw-r--r--src/svg/qsvghandler.cpp23
1 files changed, 13 insertions, 10 deletions
diff --git a/src/svg/qsvghandler.cpp b/src/svg/qsvghandler.cpp
index e2c3d92..35b8595 100644
--- a/src/svg/qsvghandler.cpp
+++ b/src/svg/qsvghandler.cpp
@@ -810,24 +810,27 @@ static bool resolveColor(const QStringRef &colorStr, QColor &color, QSvgHandler
case 'r':
{
- // starts with "rgb("
- if (colorStrTr == QLatin1String("rgb(")) {
+ // starts with "rgb(", ends with ")" and consists of at least 7 characters "rgb(,,)"
+ if (colorStrTr.length() >= 7 && colorStrTr.at(colorStrTr.length() - 1) == QLatin1Char(')')
+ && QStringRef(colorStrTr.string(), colorStrTr.position(), 4) == QLatin1String("rgb(")) {
const QChar *s = colorStrTr.constData() + 4;
QVector<qreal> compo = parseNumbersList(s);
//1 means that it failed after reaching non-parsable
//character which is going to be "%"
if (compo.size() == 1) {
- const QChar *s = colorStrTr.constData() + 4;
+ s = colorStrTr.constData() + 4;
compo = parsePercentageList(s);
- compo[0] *= (qreal)2.55;
- compo[1] *= (qreal)2.55;
- compo[2] *= (qreal)2.55;
+ for (int i = 0; i < compo.size(); ++i)
+ compo[i] *= (qreal)2.55;
}
- color = QColor(int(compo[0]),
- int(compo[1]),
- int(compo[2]));
- return true;
+ if (compo.size() == 3) {
+ color = QColor(int(compo[0]),
+ int(compo[1]),
+ int(compo[2]));
+ return true;
+ }
+ return false;
}
}
break;