From 8397a44bedf542b53284674c87268819f4911d31 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Wed, 22 Feb 2012 16:17:30 +0100 Subject: 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 Reviewed-by: Lars Knoll --- qmake/generators/integrity/gbuild.cpp | 4 ++-- qmake/generators/mac/pbuilder_pbx.cpp | 2 +- qmake/generators/makefiledeps.cpp | 4 ++-- qmake/generators/win32/msvc_objectmodel.cpp | 2 +- qmake/generators/win32/msvc_objectmodel.h | 2 +- qmake/project.cpp | 10 +++++----- 6 files changed, 12 insertions(+), 12 deletions(-) (limited to 'qmake') diff --git a/qmake/generators/integrity/gbuild.cpp b/qmake/generators/integrity/gbuild.cpp index c72c120f39..895df24193 100644 --- a/qmake/generators/integrity/gbuild.cpp +++ b/qmake/generators/integrity/gbuild.cpp @@ -213,7 +213,7 @@ GBuildMakefileGenerator::write() dllbase += DLLOFFSET; } - warn_msg(WarnParser, Option::output.fileName().toAscii()); + warn_msg(WarnParser, Option::output.fileName().toAscii().constData()); QTextStream t(&Option::output); QString primaryTarget(project->values("QMAKE_CXX").at(0)); @@ -425,7 +425,7 @@ GBuildMakefileGenerator::openOutput(QFile &file, const QString &build) const outputName += QDir::separator(); outputName += fileInfo(project->projectFile()).baseName(); outputName += projectSuffix(); - warn_msg(WarnParser, outputName.toAscii()); + warn_msg(WarnParser, outputName.toAscii().constData()); file.setFileName(outputName); } debug_msg(1, "file is %s", file.fileName().toLatin1().constData()); diff --git a/qmake/generators/mac/pbuilder_pbx.cpp b/qmake/generators/mac/pbuilder_pbx.cpp index b78ebd136d..2f6b30fe12 100644 --- a/qmake/generators/mac/pbuilder_pbx.cpp +++ b/qmake/generators/mac/pbuilder_pbx.cpp @@ -1374,7 +1374,7 @@ ProjectBuilderMakefileGenerator::writeMakeParts(QTextStream &t) } tmp = project->values("QMAKE_PBX_VARS"); for(int i = 0; i < tmp.count(); i++) { - QString var = tmp[i], val = qgetenv(var.toLatin1()); + QString var = tmp[i], val = QString::fromAscii(qgetenv(var.toLatin1().constData())); if(val.isEmpty() && var == "TB") val = "/usr/bin/"; t << "\t\t\t\t" << writeSettings(var, escapeFilePath(val)) << ";" << "\n"; diff --git a/qmake/generators/makefiledeps.cpp b/qmake/generators/makefiledeps.cpp index d28d48b4d0..642dd97e68 100644 --- a/qmake/generators/makefiledeps.cpp +++ b/qmake/generators/makefiledeps.cpp @@ -185,9 +185,9 @@ SourceFile *SourceFiles::lookupFile(const char *file) void SourceFiles::addFile(SourceFile *p, const char *k, bool own_file) { - QByteArray ba = p->file.local().toLatin1(); + const QByteArray ba = p->file.local().toLatin1(); if(!k) - k = ba; + k = ba.constData(); int h = hash(k) % num_nodes; SourceFileNode *pn = new SourceFileNode; pn->own_file = own_file; diff --git a/qmake/generators/win32/msvc_objectmodel.cpp b/qmake/generators/win32/msvc_objectmodel.cpp index 81f541f94e..e0f55a64c9 100644 --- a/qmake/generators/win32/msvc_objectmodel.cpp +++ b/qmake/generators/win32/msvc_objectmodel.cpp @@ -1615,7 +1615,7 @@ bool VCLinkerTool::parseOption(const char* option) { // Split up in subsystem, and version number QStringList both = QString(option+11).split(","); - switch (elfHash(both[0].toLatin1())) { + switch (elfHash(both[0].toLatin1().constData())) { case 0x8438445: // CONSOLE SubSystem = subSystemConsole; break; diff --git a/qmake/generators/win32/msvc_objectmodel.h b/qmake/generators/win32/msvc_objectmodel.h index 8b1cf519ff..37d923f9c1 100644 --- a/qmake/generators/win32/msvc_objectmodel.h +++ b/qmake/generators/win32/msvc_objectmodel.h @@ -477,7 +477,7 @@ protected: public: void parseOptions(QStringList& options) { for (QStringList::ConstIterator it=options.begin(); (it!=options.end()); it++) - parseOption((*it).toLatin1()); + parseOption((*it).toLatin1().constData()); } static QStringList fixCommandLine(const QString &input); }; diff --git a/qmake/project.cpp b/qmake/project.cpp index 2029e068ec..379854ed6a 100644 --- a/qmake/project.cpp +++ b/qmake/project.cpp @@ -1520,7 +1520,7 @@ QMakeProject::resolveSpec(QString *spec, const QString &qmakespec) if (*spec == "default") { #ifdef Q_OS_UNIX char buffer[1024]; - int l = readlink(qmakespec.toLatin1(), buffer, 1023); + int l = readlink(qmakespec.toLatin1().constData(), buffer, 1023); if (l != -1) { buffer[l] = '\0'; *spec = QString::fromLatin1(buffer); @@ -2070,7 +2070,7 @@ QMakeProject::doProjectExpand(QString func, QList args_list, if(args.count() > 1) singleLine = (args[1].toLower() == "true"); QString output; - FILE *proc = QT_POPEN(args[0].toLatin1(), "r"); + FILE *proc = QT_POPEN(args[0].toLatin1().constData(), "r"); while(proc && !feof(proc)) { int read_in = int(fread(buff, 1, 255, proc)); if(!read_in) @@ -3150,12 +3150,12 @@ QStringList &QMakeProject::values(const QString &_var, QHash