From ed46f774a502506c35c3f80cea6bb679d10453c0 Mon Sep 17 00:00:00 2001 From: Lorenzo <Akubi@users.noreply.github.com> Date: Sun, 1 Oct 2017 11:29:53 +0200 Subject: [PATCH] Correct Request Class memory allocation (#214) --- NodeManager.cpp | 10 ++++++---- NodeManager.h | 3 ++- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/NodeManager.cpp b/NodeManager.cpp index 72ec159..b9b37f9 100644 --- a/NodeManager.cpp +++ b/NodeManager.cpp @@ -164,12 +164,14 @@ float Timer::getElapsed() { */ Request::Request(const char* string) { - char str[10]; char* ptr; - strcpy(str,string); + // copy to working area + strcpy((char*)&_value, string); // tokenize the string and split function from value - strtok_r(str,",",&ptr); - _function = atoi(str); + strtok_r(_value, ",", &ptr); + // get function code + _function = atoi(_value); + // move user data to working area strcpy(_value,ptr); #if DEBUG == 1 Serial.print(F("REQ F=")); diff --git a/NodeManager.h b/NodeManager.h index 54c6e0b..220edaf 100644 --- a/NodeManager.h +++ b/NodeManager.h @@ -492,7 +492,8 @@ class Request { private: NodeManager* _node_manager; int _function; - char* _value; + // Size of buffer to prevent overrun + char _value[MAX_PAYLOAD+1]; }; /*************************************** -- GitLab