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_TOKENS 10
|
||||||
|
#define MAX_CMD_LEN 50
|
||||||
|
|
||||||
static uint32_t color_txt = 0;
|
static uint32_t color_txt = 0;
|
||||||
static uint32_t color_bg = 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) {
|
static err_t tcp_cmd_recv_new(void* arg, struct tcp_pcb* pcb, struct pbuf* p, err_t err) {
|
||||||
int argc = 0;
|
int argc = 0;
|
||||||
char* argv[MAX_TOKENS];
|
char* argv[MAX_TOKENS];
|
||||||
|
char cmd[MAX_CMD_LEN];
|
||||||
|
|
||||||
LWIP_UNUSED_ARG(arg);
|
LWIP_UNUSED_ARG(arg);
|
||||||
if (err == ERR_OK && p != NULL) {
|
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;
|
char* next;
|
||||||
|
|
||||||
// Make sure the string is null terminated
|
// Make sure the string is null terminated
|
||||||
p->payload = realloc(p->payload, p->len + 1);
|
int len = p->len >= MAX_CMD_LEN ? MAX_CMD_LEN : p->len;
|
||||||
p->tot_len = p->len + 1;
|
memcpy(cmd, p->payload, len);
|
||||||
((char*)(p->payload))[p->len] = '\0';
|
cmd[len] = '\0';
|
||||||
|
|
||||||
remove_newline((char*)(p->payload));
|
remove_newline((char*)(p->payload));
|
||||||
// Split string into tokens by delimiter (space)
|
// Split string into tokens by delimiter (space)
|
||||||
|
|||||||
Reference in New Issue
Block a user