Skip to content

Commit

Permalink
Merge pull request #1060 from deXol/develop
Browse files Browse the repository at this point in the history
Move getUntilNullByte to a function for QByteArray
  • Loading branch information
limpkin authored Jun 29, 2022
2 parents 52e54fc + 603b514 commit 1179e28
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
9 changes: 9 additions & 0 deletions src/Common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -514,3 +514,12 @@ QString Common::getMcAgent()
}
return "";
}

QByteArray Common::getUntilNullByte(const QByteArray &arr)
{
if (arr.contains(ZERO_BYTE))
{
return arr.left(arr.indexOf(ZERO_BYTE));
}
return arr;
}
3 changes: 3 additions & 0 deletions src/Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,8 @@ class Common

static QString getMcAgent();

static QByteArray getUntilNullByte(const QByteArray& arr);

typedef enum
{
MP_Classic = 0,
Expand Down Expand Up @@ -352,6 +354,7 @@ class Common
static const int BLE_LATEST_BUNDLE_VERSION = 7;
static const int BLE_BUNDLE_WITH_NOTES = 1;
static const int BLE_BUNDLE_WITH_BLE_NAME = 9;
static const char ZERO_BYTE = static_cast<char>(0x00);
};

struct FidoCredential
Expand Down
6 changes: 1 addition & 5 deletions src/MPDeviceBleImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1913,11 +1913,7 @@ void MPDeviceBleImpl::getBleName(const MessageHandlerCbData &cb)
bleNameArr = DEFAULT_BLE_NAME.toUtf8();
qWarning() << "Invalid character in BLE name";
}
if (bleNameArr.contains(ZERO_BYTE))
{
// Cut zero bytes from the end of the array
bleNameArr = bleNameArr.left(bleNameArr.indexOf(ZERO_BYTE));
}
bleNameArr = Common::getUntilNullByte(bleNameArr);
cb(true, "", bleNameArr);
});

Expand Down

0 comments on commit 1179e28

Please sign in to comment.