Commit 9dfc499e authored by Marc Mutz's avatar Marc Mutz Committed by The Qt Project
Browse files

QAbstractXmlNodeModel: avoid undefined behavior

In 409655f3

, 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: default avatarOlivier Goffart <ogoffart@woboq.com>
Reviewed-by: default avatarThiago Macieira <thiago.macieira@intel.com>
parent c5704288
Showing with 2 additions and 4 deletions
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment