From 1dfc22858ae907fca550a59f06b571ec22d35730 Mon Sep 17 00:00:00 2001 From: Thulinma Date: Wed, 18 May 2016 16:16:42 +0200 Subject: [PATCH] streamName and connector string data are now properly null-terminated in sharedStats structures, using snprintf. --- lib/shared_memory.cpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/lib/shared_memory.cpp b/lib/shared_memory.cpp index 574ec71a..39b50e1b 100644 --- a/lib/shared_memory.cpp +++ b/lib/shared_memory.cpp @@ -676,10 +676,7 @@ namespace IPC { if (splitChar != std::string::npos) { name[splitChar] = '+'; } - memcpy(data + 48, name.c_str(), std::min((int)name.size(), 100)); - if (name.size() < 100){ - data[48+name.size()] = 0; - } + snprintf(data+48, 100, "%s", name.c_str()); } ///\brief Gets the name of the stream this user is viewing @@ -689,7 +686,7 @@ namespace IPC { ///\brief Sets the name of the connector through which this user is viewing void statExchange::connector(std::string name) { - memcpy(data + 148, name.c_str(), std::min((int)name.size(), 20)); + snprintf(data+148, 20, "%s", name.c_str()); } ///\brief Gets the name of the connector through which this user is viewing