From 4342e3bbd0a242c401d8238612936ade0fd2a514 Mon Sep 17 00:00:00 2001 From: Pascal Serrarens Date: Mon, 24 Feb 2025 09:11:35 +0100 Subject: [PATCH] Fixed warnings --- Messages/ModelUrlMsg.cpp | 2 +- Messages/NameMsg.cpp | 2 +- Participant.cpp | 5 +++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Messages/ModelUrlMsg.cpp b/Messages/ModelUrlMsg.cpp index b70f1af..4d30d6a 100644 --- a/Messages/ModelUrlMsg.cpp +++ b/Messages/ModelUrlMsg.cpp @@ -30,7 +30,7 @@ ModelUrlMsg::ModelUrlMsg(unsigned char networkId, Thing *thing) { if (thing->modelUrl == nullptr) this->urlLength = 0; else - this->urlLength = strlen(thing->modelUrl); + this->urlLength = (unsigned char)strlen(thing->modelUrl); this->url = thing->modelUrl; // dangerous! } diff --git a/Messages/NameMsg.cpp b/Messages/NameMsg.cpp index 9f926ce..d1f1992 100644 --- a/Messages/NameMsg.cpp +++ b/Messages/NameMsg.cpp @@ -11,7 +11,7 @@ NameMsg::NameMsg(unsigned char networkId, Thing *thing) { if (thing->name == nullptr) this->nameLength = 0; else - this->nameLength = strlen(thing->name); + this->nameLength = (unsigned char)strlen(thing->name); this->name = thing->name; // dangerous! } diff --git a/Participant.cpp b/Participant.cpp index 1f432a9..85ba22f 100644 --- a/Participant.cpp +++ b/Participant.cpp @@ -252,8 +252,9 @@ void Participant::Process(RemoteParticipant* sender, NameMsg* msg) { Thing* thing = sender->Get(msg->networkId, msg->thingId); if (thing != nullptr) { int nameLength = msg->nameLength; - char* thingName = new char[nameLength + 1]; - strcpy(thingName, msg->name); + int stringLen = nameLength + 1; + char* thingName = new char[stringLen]; + strcpy_s(thingName, stringLen, msg->name); thingName[nameLength] = '\0'; thing->name = thingName; std::cout << "thing name = " << thing->name << " length = " << nameLength << "\n";