summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2012-02-22 16:17:30 +0100
committerQt by Nokia <qt-info@nokia.com>2012-02-26 09:14:11 +0100
commit8397a44bedf542b53284674c87268819f4911d31 (patch)
treecb3dd1025c99aaac9716d62a39ad3a6a5a17babf /src/corelib/tools
parentddf4b378f1e7eac62bd504a1e453cb7b894e21f2 (diff)
QByteArray: deprecate QT_NO_CAST_FROM_BYTEARRAY-protected operators
The QByteArray::operator const {char,void}*() implicit conversions are a source of subtle bugs, so they right- fully can be disabled with QT_NO_CAST_FROM_BYTEARRAY. const char *d = qstring.toLatin1(); // implicit conversion while ( d ) // oops: d points to freed memory // ... But almost no-one ever enabled this macros in the wild and many were bitten by these implicit conversions, so this patch deprecates them. I would have liked to remove them completely, but there are just too many occurrences even in Qt itself to hope to find all conditionally-compiled code that uses these. Also fixes all code that needs to compile under QT_NO_DEPRECATED (in qmake/, src/tools/). I984706452db7d0841620a0f64e179906123f3849 separately deals with the bulk of changes in src/ and examples/. Depends on I5ea1ad3c96d9e64167be53c0c418c7b7dba51f68. Change-Id: I8d47e6c293c80f61c6288c9f8d42fda41afe2267 Reviewed-by: David Faure <faure@kde.org> Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
Diffstat (limited to 'src/corelib/tools')
-rw-r--r--src/corelib/tools/qbytearray.cpp6
-rw-r--r--src/corelib/tools/qbytearray.h12
-rw-r--r--src/corelib/tools/qlocale_unix.cpp2
-rw-r--r--src/corelib/tools/qstring.cpp2
4 files changed, 10 insertions, 12 deletions
diff --git a/src/corelib/tools/qbytearray.cpp b/src/corelib/tools/qbytearray.cpp
index c74c61999d..1d37f578b8 100644
--- a/src/corelib/tools/qbytearray.cpp
+++ b/src/corelib/tools/qbytearray.cpp
@@ -343,7 +343,7 @@ int qstrcmp(const QByteArray &str1, const QByteArray &str2)
{
int l1 = str1.length();
int l2 = str2.length();
- int ret = memcmp(str1, str2, qMin(l1, l2));
+ int ret = memcmp(str1.constData(), str2.constData(), qMin(l1, l2));
if (ret != 0)
return ret;
@@ -995,6 +995,8 @@ QByteArray &QByteArray::operator=(const char *str)
/*! \fn QByteArray::operator const char *() const
\fn QByteArray::operator const void *() const
+ \obsolete Use constData() instead.
+
Returns a pointer to the data stored in the byte array. The
pointer can be used to access the bytes that compose the array.
The data is '\\0'-terminated. The pointer remains valid as long
@@ -2751,7 +2753,7 @@ QDataStream &operator<<(QDataStream &out, const QByteArray &ba)
out << (quint32)0xffffffff;
return out;
}
- return out.writeBytes(ba, ba.size());
+ return out.writeBytes(ba.constData(), ba.size());
}
/*! \relates QByteArray
diff --git a/src/corelib/tools/qbytearray.h b/src/corelib/tools/qbytearray.h
index 8202097da5..09c43988fd 100644
--- a/src/corelib/tools/qbytearray.h
+++ b/src/corelib/tools/qbytearray.h
@@ -207,8 +207,10 @@ public:
void squeeze();
#ifndef QT_NO_CAST_FROM_BYTEARRAY
- operator const char *() const;
- operator const void *() const;
+#if QT_DEPRECATED_SINCE(5, 0)
+ QT_DEPRECATED operator const char *() const { return constData(); }
+ QT_DEPRECATED operator const void *() const { return constData(); }
+#endif
#endif
char *data();
const char *data() const;
@@ -415,12 +417,6 @@ inline char QByteArray::operator[](uint i) const
inline bool QByteArray::isEmpty() const
{ return d->size == 0; }
-#ifndef QT_NO_CAST_FROM_BYTEARRAY
-inline QByteArray::operator const char *() const
-{ return d->data(); }
-inline QByteArray::operator const void *() const
-{ return d->data(); }
-#endif
inline char *QByteArray::data()
{ detach(); return d->data(); }
inline const char *QByteArray::data() const
diff --git a/src/corelib/tools/qlocale_unix.cpp b/src/corelib/tools/qlocale_unix.cpp
index 6ace96f771..f2876912b4 100644
--- a/src/corelib/tools/qlocale_unix.cpp
+++ b/src/corelib/tools/qlocale_unix.cpp
@@ -98,7 +98,7 @@ QLocale QSystemLocale::fallbackLocale() const
lang = qgetenv("LC_NUMERIC");
if (lang.isEmpty())
lang = qgetenv("LANG");
- return QLocale(QLatin1String(lang));
+ return QLocale(QString::fromLatin1(lang));
}
QVariant QSystemLocale::query(QueryType type, QVariant in) const
diff --git a/src/corelib/tools/qstring.cpp b/src/corelib/tools/qstring.cpp
index 704545667c..14b8782dae 100644
--- a/src/corelib/tools/qstring.cpp
+++ b/src/corelib/tools/qstring.cpp
@@ -4761,7 +4761,7 @@ int QString::localeAwareCompare_helper(const QChar *data1, int length1,
} // else fall through
# endif
// declared in <string.h>
- int delta = strcoll(toLocal8Bit_helper(data1, length1), toLocal8Bit_helper(data2, length2));
+ int delta = strcoll(toLocal8Bit_helper(data1, length1).constData(), toLocal8Bit_helper(data2, length2).constData());
if (delta == 0)
delta = ucstrcmp(data1, length1, data2, length2);
return delta;