From 9dfc499e6cde23d5fdcd993c435eb601fc5de1fb Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Tue, 5 Nov 2013 14:01:11 +0100 Subject: 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 Reviewed-by: Thiago Macieira --- src/xmlpatterns/api/qabstractxmlnodemodel.h | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/xmlpatterns/api/qabstractxmlnodemodel.h b/src/xmlpatterns/api/qabstractxmlnodemodel.h index 98148f71..363d6d39 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(qptrdiff(data)); } Data additionalData; -- cgit v1.2.3