Skip to content

Commit

Permalink
Update to make sure we don't decrement outside of buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
ovyl-dave-sabol committed Jan 19, 2024
1 parent db9ba93 commit 10d35d0
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ cli_status_t cli_put(cli_t *cli, char c)
{
case CMD_TERMINATOR:
{
/* Terminate the msg and reset the msg ptr by subtracting the length. This should put us back at the begining of the array */
*rx_data.buf_ptr = '\0';
/* Terminate the msg and reset the msg ptr by subtracting the length. This should put us back at the beginning of the array */
*rx_data.buf_ptr = '\0';
rx_data.buf_ptr -= rx_data.current_buf_length;
rx_data.is_ready = true;
rx_data.current_buf_length = 0;
Expand All @@ -137,10 +137,12 @@ cli_status_t cli_put(cli_t *cli, char c)
/* Normal character received, add to buffer. */
if(rx_data.current_buf_length < rx_data.buf_size)
{
/* check for backspace or delete*/
/* If backspace or delete remove character if we aren't at the beginning of the buffer */
if(c == 127 || c == 8){
*rx_data.buf_ptr-- = '\0';
rx_data.current_buf_length--;
if(rx_data.current_buf_length > 0){
*rx_data.buf_ptr-- = '\0';
rx_data.current_buf_length--;
}
}else{
*rx_data.buf_ptr++ = c;
rx_data.current_buf_length++;
Expand Down

0 comments on commit 10d35d0

Please sign in to comment.