diff options
author | Thiago Macieira <thiago@kde.org> | 2011-07-21 16:33:17 +0200 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2011-07-21 18:56:02 +0200 |
commit | 001bd63e813cf19d1d6abbbfeb2599e6804807d5 (patch) | |
tree | 5f9947b973fca9e27a9f91628ba69405a51a89a5 /src/corelib/tools/qbytearray.h | |
parent | 74a6fe79d999178de9d16befe7547af2d2f9f698 (diff) |
Make the N parameter to the QXXXLiterals be the actual string length
Before, it was the length + 1, to include the ending NUL or
U+0000. This avoids mistakes of -1 in QStringBuilder and will allow us
simpler code in the User-Defined Literal (future improvement)
Change-Id: I75c47d6c44579124888f925e240817229347dc70
Merge-request: 31
Reviewed-by: Olivier Goffart <olivier.goffart@nokia.com>
Reviewed-on: http://codereview.qt.nokia.com/1966
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Diffstat (limited to 'src/corelib/tools/qbytearray.h')
-rw-r--r-- | src/corelib/tools/qbytearray.h | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/src/corelib/tools/qbytearray.h b/src/corelib/tools/qbytearray.h index dbac302d05..4190ffa18a 100644 --- a/src/corelib/tools/qbytearray.h +++ b/src/corelib/tools/qbytearray.h @@ -133,10 +133,10 @@ struct QByteArrayData inline const char *data() const { return d + sizeof(qptrdiff) + offset; } }; -template<int n> struct QConstByteArrayData +template<int N> struct QConstByteArrayData { const QByteArrayData ba; - const char data[n]; + const char data[N + 1]; }; template<int N> struct QConstByteArrayDataPtr @@ -147,9 +147,9 @@ template<int N> struct QConstByteArrayDataPtr #if defined(Q_COMPILER_LAMBDA) # define QByteArrayLiteral(str) ([]() { \ - enum { Size = sizeof(str) }; \ + enum { Size = sizeof(str) - 1 }; \ static const QConstByteArrayData<Size> qbytearray_literal = \ - { { Q_REFCOUNT_INITIALIZER(-1), Size -1, 0, 0, { 0 } }, str }; \ + { { Q_REFCOUNT_INITIALIZER(-1), Size, 0, 0, { 0 } }, str }; \ QConstByteArrayDataPtr<Size> holder = { &qbytearray_literal }; \ return holder; }()) @@ -160,9 +160,9 @@ template<int N> struct QConstByteArrayDataPtr # define QByteArrayLiteral(str) \ __extension__ ({ \ - enum { Size = sizeof(str) }; \ + enum { Size = sizeof(str) - 1 }; \ static const QConstByteArrayData<Size> qbytearray_literal = \ - { { Q_REFCOUNT_INITIALIZER(-1), Size -1, 0, 0, { 0 } }, str }; \ + { { Q_REFCOUNT_INITIALIZER(-1), Size, 0, 0, { 0 } }, str }; \ QConstByteArrayDataPtr<Size> holder = { &qbytearray_literal }; \ holder; }) #endif |