From c19508179d1b75d16b0e08aff6afc2790c8bc650 Mon Sep 17 00:00:00 2001 From: Pascal Serrarens Date: Sun, 2 Feb 2025 14:38:12 +0100 Subject: [PATCH] Thing name processing fix --- Participant.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/Participant.cpp b/Participant.cpp index 77e5381..fa595d5 100644 --- a/Participant.cpp +++ b/Participant.cpp @@ -256,10 +256,13 @@ void Participant::Process(ThingMsg *msg) {} void Participant::Process(NameMsg *msg) { Thing *thing = this->Get(msg->networkId, msg->thingId); if (thing != nullptr) { - char *thingName = new char[strlen(msg->name)]; + int nameLength = msg->nameLength; + char *thingName = new char[nameLength + 1]; strcpy(thingName, msg->name); + thingName[nameLength] = '\0'; thing->name = thingName; - std::cout << "thing name = " << thing->name << "\n"; + std::cout << "thing name = " << thing->name << " length = " << nameLength + << "\n"; } } @@ -272,7 +275,7 @@ void Participant::Process(CustomMsg *msg) { else std::cout << "custom msg for unknown thing " << (int)msg->networkId << ":" << (int)msg->thingId << "\n"; - std::cout << "Processed custom msg\n"; + // std::cout << "Processed custom msg\n"; } // Receive @@ -281,8 +284,8 @@ void Participant::Process(CustomMsg *msg) { #pragma region Things Thing *Participant::Get(unsigned char networkId, unsigned char thingId) { - std::cout << "Get " << (int)networkId << "/" << (int)thingId << " from " - << this->things.size() << " things\n"; + // std::cout << "Get " << (int)networkId << "/" << (int)thingId << " from " + // << this->things.size() << " things\n"; for (auto &thing : this->things) { // std::cout << " ? " << (int)thing->networkId << "/" << (int)thing->id // << "\n";