summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools/qbytearray.cpp
diff options
context:
space:
mode:
authorQt Continuous Integration System <qt-info@nokia.com>2010-01-12 09:42:00 (GMT)
committerQt Continuous Integration System <qt-info@nokia.com>2010-01-12 09:42:00 (GMT)
commit10a0134c5a3b40d3fc5e6d43a753eca62c008166 (patch)
treed4c191e9e25505c2b083bc0eefc3f571f9d4f9c5 /src/corelib/tools/qbytearray.cpp
parentbf71ab63e805e49e59fbe25265104a414ab7d039 (diff)
parent2efba0002d26b584c771aa9260e6d699e5ff8da3 (diff)
downloadQt-10a0134c5a3b40d3fc5e6d43a753eca62c008166.zip
Qt-10a0134c5a3b40d3fc5e6d43a753eca62c008166.tar.gz
Qt-10a0134c5a3b40d3fc5e6d43a753eca62c008166.tar.bz2
Merge branch '4.6' of scm.dev.nokia.troll.no:qt/oslo-staging-1 into 4.6-integration
* '4.6' of scm.dev.nokia.troll.no:qt/oslo-staging-1: (73 commits) doc: update snippets for QtScript function expressions Prevent a crash when creating an inputContext from the QApplication dtor. QNAM HTTP Code: Cache socket state inside ensureConnection() tst_qhttpnetworkconnection: Test also HEAD in some tests tst_qhttpnetworkconnection: Relax condition in getMultipleWithPriorities QNAM HTTP Code: When starting new request, prefer connected sockets. typo fix Added the 'framecapture' WebKit example to the default build. Fix code example fix typo in qreadwritelock's documentation QNAM HTTP: Don't call d_func() so often QNAM HTTP: Fix readBuffer maximum size. QNAM HTTP: Optimize eatWhitespace() QNAM HTTP: Check if socket already tries to connect. network internals: fix build on S60 [syncqt] Make -separate-module work with WebKit's directory structure doc: Corrected explanation of when append() does nothing. doc: Added clarification about allocating space for the 0 terminator. Add a way to access the normalised URL in QUrl. [syncqt] Make it possible to synchronize headers for a separate module ...
Diffstat (limited to 'src/corelib/tools/qbytearray.cpp')
-rw-r--r--src/corelib/tools/qbytearray.cpp25
1 files changed, 19 insertions, 6 deletions
diff --git a/src/corelib/tools/qbytearray.cpp b/src/corelib/tools/qbytearray.cpp
index bf9b6bd..d2fbf5a 100644
--- a/src/corelib/tools/qbytearray.cpp
+++ b/src/corelib/tools/qbytearray.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
@@ -903,8 +903,8 @@ QByteArray &QByteArray::operator=(const char *str)
The last byte in the byte array is at position size() - 1. In
addition, QByteArray ensures that the byte at position size() is
always '\\0', so that you can use the return value of data() and
- constData() as arguments to functions that expect
- '\\0'-terminated strings.
+ constData() as arguments to functions that expect '\\0'-terminated
+ strings.
Example:
\snippet doc/src/snippets/code/src_corelib_tools_qbytearray.cpp 6
@@ -997,7 +997,9 @@ QByteArray &QByteArray::operator=(const char *str)
Returns a pointer to the data stored in the byte array. The
pointer can be used to access and modify the bytes that compose
- the array. The data is '\\0'-terminated.
+ the array. The data is '\\0'-terminated, i.e. the number of
+ bytes in the returned character string is size() + 1 for the
+ '\\0' terminator.
Example:
\snippet doc/src/snippets/code/src_corelib_tools_qbytearray.cpp 8
@@ -1009,6 +1011,16 @@ QByteArray &QByteArray::operator=(const char *str)
This function is mostly useful to pass a byte array to a function
that accepts a \c{const char *}.
+ The following example makes a copy of the char* returned by
+ data(), but it will corrupt the heap and cause a crash because it
+ does not allocate a byte for the '\\0' at the end:
+
+ \snippet doc/src/snippets/code/src_corelib_tools_qbytearray.cpp 46
+
+ This one allocates the correct amount of space:
+
+ \snippet doc/src/snippets/code/src_corelib_tools_qbytearray.cpp 47
+
Note: A QByteArray can store any byte values including '\\0's,
but most functions that take \c{char *} arguments assume that the
data ends at the first '\\0' they encounter.
@@ -1591,8 +1603,9 @@ QByteArray& QByteArray::append(const char *str)
array and returns a reference to this byte array.
If \a len is negative, the length of the string will be determined
- automatically using qstrlen(). If \a len is zero or the length of the
- string is zero, nothing will be appended to the byte array.
+ automatically using qstrlen(). If \a len is zero or \a str is
+ null, nothing is appended to the byte array. Ensure that \a len is
+ \e not longer than \a str.
*/
QByteArray &QByteArray::append(const char *str, int len)