summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools/qstring.h
diff options
context:
space:
mode:
authorJoão Abecasis <joao.abecasis@nokia.com>2012-04-04 15:00:41 +0200
committerQt by Nokia <qt-info@nokia.com>2012-04-11 02:26:41 +0200
commit6abfc992b9d70837d42fcef3f2e2637464063899 (patch)
tree61cc582bba6fba2dc49e5d3d20cebb656895ca40 /src/corelib/tools/qstring.h
parentd4f3052a1b210c09976883afbe0fac087171be4f (diff)
Make reallocData() take (unsigned) size, including null
The parameter represents an allocation size and unsigned matches the Q*Data::alloc member it ultimately represents (even if they currently differ in accounting for the null). There's still work up for grabs to ensure we avoid integer overflows when growing. Change-Id: Ib092fec37ec2ceed37bebfdc52e2de27b336328f Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/tools/qstring.h')
-rw-r--r--src/corelib/tools/qstring.h10
1 files changed, 5 insertions, 5 deletions
diff --git a/src/corelib/tools/qstring.h b/src/corelib/tools/qstring.h
index d09e3b5ab2..a902f5f375 100644
--- a/src/corelib/tools/qstring.h
+++ b/src/corelib/tools/qstring.h
@@ -370,7 +370,7 @@ public:
inline QString &operator+=(QChar c) {
if (d->ref.isShared() || d->size + 1 > int(d->alloc))
- reallocData(d->size + 1, true);
+ reallocData(uint(d->size) + 2u, true);
d->data()[d->size++] = c.unicode();
d->data()[d->size] = '\0';
return *this;
@@ -646,7 +646,7 @@ private:
Data *d;
static void free(Data *);
- void reallocData(int alloc, bool grow = false);
+ void reallocData(uint alloc, bool grow = false);
void expand(int i);
void updateProperties() const;
QString multiArg(int numArgs, const QString **args) const;
@@ -742,7 +742,7 @@ inline QChar *QString::data()
inline const QChar *QString::constData() const
{ return reinterpret_cast<const QChar*>(d->data()); }
inline void QString::detach()
-{ if (d->ref.isShared() || (d->offset != sizeof(QStringData))) reallocData(d->size); }
+{ if (d->ref.isShared() || (d->offset != sizeof(QStringData))) reallocData(uint(d->size) + 1u); }
inline bool QString::isDetached() const
{ return !d->ref.isShared(); }
inline QString &QString::operator=(const QLatin1String &s)
@@ -908,7 +908,7 @@ inline QString::~QString() { if (!d->ref.deref()) free(d); }
inline void QString::reserve(int asize)
{
if (d->ref.isShared() || asize > int(d->alloc))
- reallocData(asize);
+ reallocData(uint(asize) + 1u);
if (!d->capacityReserved) {
// cannot set unconditionally, since d could be the shared_null/shared_empty (which is const)
@@ -919,7 +919,7 @@ inline void QString::reserve(int asize)
inline void QString::squeeze()
{
if (d->ref.isShared() || d->size < int(d->alloc))
- reallocData(d->size);
+ reallocData(uint(d->size) + 1u);
if (d->capacityReserved) {
// cannot set unconditionally, since d could be shared_null or