summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2013-11-05 14:01:11 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-11-05 21:26:26 +0100
commit9dfc499e6cde23d5fdcd993c435eb601fc5de1fb (patch)
tree3d7db92111bfb7dd1f2ee8a4a643575f756d308d /src
parentc570428816e3719ba2f5efa5d2c8c88170a085b3 (diff)
downloadqtxmlpatterns-9dfc499e6cde23d5fdcd993c435eb601fc5de1fb.tar.gz
QAbstractXmlNodeModel: avoid undefined behavior
In 409655f3451815930b70a71baa175ab9f34467ed, the C-style cast was replaced by pointer arithmetic: char *null = 0; return null + offset; Says the standard (5.7 [expr.add]/5): When an expression that has integral type is added to or subtracted from a pointer, [...] If both the pointer operand and the result point to elements of the same array object, or one past the last element of the array object, the evaluation shall not produce an overflow; otherwise, the behavior is undefined. Iow: the above code has undefined behaviour. Fix by going back to the casting version, but using a C++ reinterpret_cast instead of a C-style one. Task-number: QTBUG-32735 Change-Id: Ia774491b13b1c52089daf63a7921b163fc93abce Reviewed-by: Olivier Goffart <ogoffart@woboq.com> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src')
-rw-r--r--src/xmlpatterns/api/qabstractxmlnodemodel.h6
1 files changed, 2 insertions, 4 deletions
diff --git a/src/xmlpatterns/api/qabstractxmlnodemodel.h b/src/xmlpatterns/api/qabstractxmlnodemodel.h
index 98148f7..363d6d3 100644
--- a/src/xmlpatterns/api/qabstractxmlnodemodel.h
+++ b/src/xmlpatterns/api/qabstractxmlnodemodel.h
@@ -92,10 +92,8 @@ namespace QPatternist
};
void *pointer() const
{
- /* Constructing to qptrdiff means we avoid warnings.
- */
- char *null = 0;
- return null + qptrdiff(data);
+ // Constructing via qptrdiff avoids warnings:
+ return reinterpret_cast<void*>(qptrdiff(data));
}
Data additionalData;