summaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2017-06-27 20:57:31 +0200
committerChristian Mollekopf <chrigi_1@fastmail.fm>2017-06-27 20:57:31 +0200
commit06f996a139a5ac660e98163fac796f94c1a6468f (patch)
treef1eca6b33e045d8e58bf2f397bbc638a136eb7e8 /common
parent0f888b18bf7e6eecc0a2aa5aaa015cf3b9c755be (diff)
downloadsink-06f996a139a5ac660e98163fac796f94c1a6468f.tar.gz
sink-06f996a139a5ac660e98163fac796f94c1a6468f.zip
Ensure we can deal with non-null terminated strings.
Diffstat (limited to 'common')
-rw-r--r--common/contactpreprocessor.cpp3
-rw-r--r--common/propertymapper.cpp16
2 files changed, 10 insertions, 9 deletions
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
36 } 36 }
37 contact.setEmails(emails); 37 contact.setEmails(emails);
38 38
39 const auto photo = addressee.photo().rawData(); 39 contact.setPhoto(addressee.photo().rawData());
40 contact.setPhoto(photo);
41} 40}
42 41
43ContactPropertyExtractor::~ContactPropertyExtractor() 42ContactPropertyExtractor::~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 <>
58flatbuffers::uoffset_t variantToProperty<QByteArray>(const QVariant &property, flatbuffers::FlatBufferBuilder &fbb) 58flatbuffers::uoffset_t variantToProperty<QByteArray>(const QVariant &property, flatbuffers::FlatBufferBuilder &fbb)
59{ 59{
60 if (property.isValid()) { 60 if (property.isValid()) {
61 return fbb.CreateString(property.toByteArray().toStdString()).o; 61 const auto ba = property.toByteArray();
62 const auto s = fbb.CreateString(ba.constData(), ba.size());
63 return s.o;
62 } 64 }
63 return 0; 65 return 0;
64} 66}
@@ -135,7 +137,7 @@ QString propertyToString(const flatbuffers::String *property)
135{ 137{
136 if (property) { 138 if (property) {
137 // We have to copy the memory, otherwise it would become eventually invalid 139 // We have to copy the memory, otherwise it would become eventually invalid
138 return QString::fromStdString(property->c_str()); 140 return QString::fromStdString(property->str());
139 } 141 }
140 return QString(); 142 return QString();
141} 143}
@@ -145,7 +147,7 @@ QVariant propertyToVariant<QString>(const flatbuffers::String *property)
145{ 147{
146 if (property) { 148 if (property) {
147 // We have to copy the memory, otherwise it would become eventually invalid 149 // We have to copy the memory, otherwise it would become eventually invalid
148 return QString::fromStdString(property->c_str()); 150 return QString::fromStdString(property->str());
149 } 151 }
150 return QVariant(); 152 return QVariant();
151} 153}
@@ -155,7 +157,7 @@ QVariant propertyToVariant<Sink::ApplicationDomain::BLOB>(const flatbuffers::Str
155{ 157{
156 if (property) { 158 if (property) {
157 // We have to copy the memory, otherwise it would become eventually invalid 159 // We have to copy the memory, otherwise it would become eventually invalid
158 auto s = QString::fromStdString(property->c_str()); 160 auto s = QString::fromStdString(property->str());
159 auto ext = s.endsWith(":ext"); 161 auto ext = s.endsWith(":ext");
160 s.chop(4); 162 s.chop(4);
161 163
@@ -171,7 +173,7 @@ QVariant propertyToVariant<Sink::ApplicationDomain::Reference>(const flatbuffers
171{ 173{
172 if (property) { 174 if (property) {
173 // We have to copy the memory, otherwise it would become eventually invalid 175 // We have to copy the memory, otherwise it would become eventually invalid
174 return QVariant::fromValue(Sink::ApplicationDomain::Reference{QString::fromStdString(property->c_str()).toUtf8()}); 176 return QVariant::fromValue(Sink::ApplicationDomain::Reference{QString::fromStdString(property->str()).toUtf8()});
175 } 177 }
176 return QVariant(); 178 return QVariant();
177} 179}
@@ -181,7 +183,7 @@ QVariant propertyToVariant<QByteArray>(const flatbuffers::String *property)
181{ 183{
182 if (property) { 184 if (property) {
183 // We have to copy the memory, otherwise it would become eventually invalid 185 // We have to copy the memory, otherwise it would become eventually invalid
184 return QString::fromStdString(property->c_str()).toUtf8(); 186 return QByteArray(property->c_str(), property->Length());
185 } 187 }
186 return QVariant(); 188 return QVariant();
187} 189}
@@ -203,7 +205,7 @@ QVariant propertyToVariant<QByteArrayList>(const flatbuffers::Vector<flatbuffers
203 QByteArrayList list; 205 QByteArrayList list;
204 for (auto it = property->begin(); it != property->end();) { 206 for (auto it = property->begin(); it != property->end();) {
205 // We have to copy the memory, otherwise it would become eventually invalid 207 // We have to copy the memory, otherwise it would become eventually invalid
206 list << QString::fromStdString((*it)->c_str()).toUtf8(); 208 list << QString::fromStdString((*it)->str()).toUtf8();
207 it.operator++(); 209 it.operator++();
208 } 210 }
209 return QVariant::fromValue(list); 211 return QVariant::fromValue(list);