QString: fix append(const QStringRef &str)
Use QStringRef::isNull instead of QStringRef::string() for validation. Non-NULL str.string() may yet leave us with a useless str.unicode(), which is the actual problem here; whereas !str.isNull() does really confirm that str.unicode() is sensible. Such test prevents situation like: const QString a; QString b; b.append(a); // b.isNull() == true b.append(QStringRef(&a)); // b.isNull() == false Auto test updated: create QStringRef from QString directly, without any condition. Change-Id: I082cd58ef656d8a53e3c1223aca01feea82fffb9 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
This commit is contained in:
parent
35117590c8
commit
9c8a8e90a6
@ -9375,7 +9375,7 @@ QString &QString::append(const QStringRef &str)
|
||||
{
|
||||
if (str.string() == this) {
|
||||
str.appendTo(this);
|
||||
} else if (str.string()) {
|
||||
} else if (!str.isNull()) {
|
||||
int oldSize = size();
|
||||
resize(oldSize + str.size());
|
||||
memcpy(data() + oldSize, str.unicode(), str.size() * sizeof(QChar));
|
||||
|
@ -131,7 +131,7 @@ template <>
|
||||
class Arg<QStringRef> : ArgBase
|
||||
{
|
||||
QStringRef ref() const
|
||||
{ return this->pinned.isNull() ? QStringRef() : this->pinned.midRef(0) ; }
|
||||
{ return QStringRef(&pinned); }
|
||||
public:
|
||||
explicit Arg(const char *str) : ArgBase(str) {}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user