tcp_cmd
change null termination from realloc to internal array
This commit is contained in:
@@ -10,6 +10,7 @@ extern "C" {
|
||||
}
|
||||
|
||||
#define MAX_TOKENS 10
|
||||
#define MAX_CMD_LEN 50
|
||||
|
||||
static uint32_t color_txt = 0;
|
||||
static uint32_t color_bg = 0;
|
||||
@@ -196,6 +197,7 @@ static void tcp_cmd_parser(struct tcp_pcb* pcb, int argc, char** argv) {
|
||||
static err_t tcp_cmd_recv_new(void* arg, struct tcp_pcb* pcb, struct pbuf* p, err_t err) {
|
||||
int argc = 0;
|
||||
char* argv[MAX_TOKENS];
|
||||
char cmd[MAX_CMD_LEN];
|
||||
|
||||
LWIP_UNUSED_ARG(arg);
|
||||
if (err == ERR_OK && p != NULL) {
|
||||
@@ -203,9 +205,9 @@ static err_t tcp_cmd_recv_new(void* arg, struct tcp_pcb* pcb, struct pbuf* p, er
|
||||
char* next;
|
||||
|
||||
// Make sure the string is null terminated
|
||||
p->payload = realloc(p->payload, p->len + 1);
|
||||
p->tot_len = p->len + 1;
|
||||
((char*)(p->payload))[p->len] = '\0';
|
||||
int len = p->len >= MAX_CMD_LEN ? MAX_CMD_LEN : p->len;
|
||||
memcpy(cmd, p->payload, len);
|
||||
cmd[len] = '\0';
|
||||
|
||||
remove_newline((char*)(p->payload));
|
||||
// Split string into tokens by delimiter (space)
|
||||
|
||||
Reference in New Issue
Block a user