Ignore:
Timestamp:
May 5, 2011, 5:36:53 AM (14 years ago)
Author:
Dmitry A. Kuminov
Message:

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/src/corelib/global/qmalloc.cpp

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
     
    9191    }
    9292
    93     union { void *ptr; void **pptr; quintptr n; } real, faked;
    94 
    9593    // qMalloc returns pointers aligned at least at sizeof(size_t) boundaries
    9694    // but usually more (8- or 16-byte boundaries).
     
    10199    // alignment anyway.
    102100
    103     real.ptr = qRealloc(actualptr, newsize + alignment);
    104     if (!real.ptr)
     101    = qRealloc(actualptr, newsize + alignment);
     102    if (!real)
    105103        return 0;
    106104
    107     faked.n = real.n + alignment;
    108     faked.n &= ~(alignment - 1);
     105    quintptr faked = reinterpret_cast<quintptr>(real) + alignment;
     106    faked &= ~(alignment - 1);
     107
     108    void **faked_ptr = reinterpret_cast<void **>(faked);
    109109
    110110    // now save the value of the real pointer at faked-sizeof(void*)
    111111    // by construction, alignment > sizeof(void*) and is a power of 2, so
    112112    // faked-sizeof(void*) is properly aligned for a pointer
    113     faked.pptr[-1] = real.ptr;
     113    faked;
    114114
    115     return faked.ptr;
     115    return fakedptr;
    116116}
    117117
     
    125125
    126126QT_END_NAMESPACE
     127
Note: See TracChangeset for help on using the changeset viewer.