aboutsummaryrefslogtreecommitdiffstats
path: root/examples/quick/scenegraph
diff options
context:
space:
mode:
authorhjk <hjk121@nokiamail.com>2014-02-04 14:02:16 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-02-05 16:40:10 +0100
commit44b16b06983ac3661f485ccfb3ffe88ba586d557 (patch)
treeb3af601cfe164733b932fbc79eff12b8c8c5596c /examples/quick/scenegraph
parentd781cc7d99fa1a1f34440ce319bacadfa4326673 (diff)
Avoid out-of-bound accesses in Qt Quick example code
Task-number: QTBUG-36197 Change-Id: I5545c36a1ce9ea6c2451c92e0e79f65e5ab26c68 Reviewed-by: Mitch Curtis <mitch.curtis@digia.com>
Diffstat (limited to 'examples/quick/scenegraph')
-rw-r--r--examples/quick/scenegraph/graph/linenode.cpp25
1 files changed, 15 insertions, 10 deletions
diff --git a/examples/quick/scenegraph/graph/linenode.cpp b/examples/quick/scenegraph/graph/linenode.cpp
index 0d1229cf1d..015aa4f0ee 100644
--- a/examples/quick/scenegraph/graph/linenode.cpp
+++ b/examples/quick/scenegraph/graph/linenode.cpp
@@ -58,17 +58,14 @@ class LineShader : public QSGSimpleMaterialShader<LineMaterial>
QSG_DECLARE_SIMPLE_SHADER(LineShader, LineMaterial)
public:
- const char *vertexShader() const {
- QResource r(":/scenegraph/graph/shaders/line.vsh");
- Q_ASSERT(r.isValid());
- return (const char *) r.data();
- }
+ LineShader()
+ : vsh(readResource(":/scenegraph/graph/shaders/line.vsh")),
+ fsh(readResource(":/scenegraph/graph/shaders/line.fsh"))
+ {}
- const char *fragmentShader() const {
- QResource r(":/scenegraph/graph/shaders/line.fsh");
- Q_ASSERT(r.isValid());
- return (const char *) r.data();
- }
+ const char *vertexShader() const { return vsh.constData(); }
+
+ const char *fragmentShader() const { return fsh.constData(); }
QList<QByteArray> attributes() const { return QList<QByteArray>() << "pos" << "t"; }
@@ -84,7 +81,15 @@ public:
id_color = program()->uniformLocation("color");
}
+ static QByteArray readResource(const char *path) {
+ QResource r(path);
+ Q_ASSERT(r.isValid());
+ return QByteArray((const char *)r.data(), r.size());
+ }
+
private:
+ QByteArray vsh;
+ QByteArray fsh;
int id_color;
int id_spread;
int id_size;