Skip to content
  • Marc Mutz's avatar
    QAbstractXmlNodeModel: avoid undefined behavior · 9dfc499e
    Marc Mutz authored
    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>
    9dfc499e