mirror of
https://github.com/h2zero/esp-nimble-cpp.git
synced 2024-11-21 20:50:55 +01:00
Fix NimBLEUtils::dataToHexString returned string, must resize before modifying.
This commit is contained in:
parent
84f4d4f897
commit
ab43135f82
1 changed files with 1 additions and 1 deletions
|
@ -500,7 +500,7 @@ const char* NimBLEUtils::gapEventToString(uint8_t eventType) {
|
||||||
std::string NimBLEUtils::dataToHexString(const uint8_t* source, uint8_t length) {
|
std::string NimBLEUtils::dataToHexString(const uint8_t* source, uint8_t length) {
|
||||||
constexpr char hexmap[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
|
constexpr char hexmap[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
|
||||||
std::string str{};
|
std::string str{};
|
||||||
str.reserve(length * 2 + 1);
|
str.resize(length * 2);
|
||||||
|
|
||||||
for (uint8_t i = 0; i < length; i++) {
|
for (uint8_t i = 0; i < length; i++) {
|
||||||
str[2 * i] = hexmap[(source[i] & 0xF0) >> 4];
|
str[2 * i] = hexmap[(source[i] & 0xF0) >> 4];
|
||||||
|
|
Loading…
Reference in a new issue