Fix incorrect uuid check due to temporary char* in QString::toUtf8()

toUtf8() creates a temporary char* representation which is assigned to
uuid. As soon the object created by toUtf8() gets destroyed, the uuid
pointer points to releases memory.

The intention is to check that we don't have one of the standard
16bit Bluetooth uuids. That's the purpose of QBluetoothUuid::toUInt16().

Signed-off-by: Alex Blasche <alexander.blasche@qt.io>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
Alex Blasche 2017-06-27 13:50:19 +02:00 committed by Linus Torvalds
parent 4f3a9cdb35
commit 81dabe5ace

View file

@ -42,13 +42,14 @@ void BLEObject::writeCompleted(const QLowEnergyDescriptor &d, const QByteArray &
void BLEObject::addService(const QBluetoothUuid &newService)
{
const char *uuid = newService.toString().toUtf8().data();
qDebug() << "Found service" << uuid;
if (uuid[1] == '0') {
qDebug () << " .. ignoring since first digit is '0'";
qDebug() << "Found service" << newService;
bool isStandardUuid = false;
newService.toUInt16(&isStandardUuid);
if (isStandardUuid) {
qDebug () << " .. ignoring standard service";
return;
}
service = controller->createServiceObject(newService, this);
qDebug() << " .. created service object" << service;
if (service) {