From 06f996a139a5ac660e98163fac796f94c1a6468f Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Tue, 27 Jun 2017 20:57:31 +0200 Subject: Ensure we can deal with non-null terminated strings. --- common/contactpreprocessor.cpp | 3 +-- common/propertymapper.cpp | 16 +++++++++------- 2 files changed, 10 insertions(+), 9 deletions(-) (limited to 'common') diff --git a/common/contactpreprocessor.cpp b/common/contactpreprocessor.cpp index 68a8acb..d331421 100644 --- a/common/contactpreprocessor.cpp +++ b/common/contactpreprocessor.cpp @@ -36,8 +36,7 @@ void updatedProperties(Sink::ApplicationDomain::Contact &contact, const KContact } contact.setEmails(emails); - const auto photo = addressee.photo().rawData(); - contact.setPhoto(photo); + contact.setPhoto(addressee.photo().rawData()); } ContactPropertyExtractor::~ContactPropertyExtractor() diff --git a/common/propertymapper.cpp b/common/propertymapper.cpp index c14a62e..dbf93a3 100644 --- a/common/propertymapper.cpp +++ b/common/propertymapper.cpp @@ -58,7 +58,9 @@ template <> flatbuffers::uoffset_t variantToProperty(const QVariant &property, flatbuffers::FlatBufferBuilder &fbb) { if (property.isValid()) { - return fbb.CreateString(property.toByteArray().toStdString()).o; + const auto ba = property.toByteArray(); + const auto s = fbb.CreateString(ba.constData(), ba.size()); + return s.o; } return 0; } @@ -135,7 +137,7 @@ QString propertyToString(const flatbuffers::String *property) { if (property) { // We have to copy the memory, otherwise it would become eventually invalid - return QString::fromStdString(property->c_str()); + return QString::fromStdString(property->str()); } return QString(); } @@ -145,7 +147,7 @@ QVariant propertyToVariant(const flatbuffers::String *property) { if (property) { // We have to copy the memory, otherwise it would become eventually invalid - return QString::fromStdString(property->c_str()); + return QString::fromStdString(property->str()); } return QVariant(); } @@ -155,7 +157,7 @@ QVariant propertyToVariant(const flatbuffers::Str { if (property) { // We have to copy the memory, otherwise it would become eventually invalid - auto s = QString::fromStdString(property->c_str()); + auto s = QString::fromStdString(property->str()); auto ext = s.endsWith(":ext"); s.chop(4); @@ -171,7 +173,7 @@ QVariant propertyToVariant(const flatbuffers { if (property) { // We have to copy the memory, otherwise it would become eventually invalid - return QVariant::fromValue(Sink::ApplicationDomain::Reference{QString::fromStdString(property->c_str()).toUtf8()}); + return QVariant::fromValue(Sink::ApplicationDomain::Reference{QString::fromStdString(property->str()).toUtf8()}); } return QVariant(); } @@ -181,7 +183,7 @@ QVariant propertyToVariant(const flatbuffers::String *property) { if (property) { // We have to copy the memory, otherwise it would become eventually invalid - return QString::fromStdString(property->c_str()).toUtf8(); + return QByteArray(property->c_str(), property->Length()); } return QVariant(); } @@ -203,7 +205,7 @@ QVariant propertyToVariant(const flatbuffers::Vectorbegin(); it != property->end();) { // We have to copy the memory, otherwise it would become eventually invalid - list << QString::fromStdString((*it)->c_str()).toUtf8(); + list << QString::fromStdString((*it)->str()).toUtf8(); it.operator++(); } return QVariant::fromValue(list); -- cgit v1.2.3