error: array subscript has type 'char' when using isdigit()
Posted: Wed Jun 07, 2023 10:49 am
Hello. In my UART0 parser I have the following function to parse the incoming data:
This function is being called when I read incomming UART data:
I think I didint have any problems with the esp-idf v4.4 but now I ported my code to esp-idf v5.0.1 and noticed this weird error:
I dont really understand what is the issue:
All I am doing is checking if the 4th byte in the char array is digit or no. For example:
red:50 is valid
red:x1 is not valid
Code: Select all
bool ParseSystemCmd(char *line, uint16_t cmd_size)
{
if (!strncmp("ping", line,4))
{
printf("pong\n");
return true;
}
if (!strncmp("red:", line,4))
{
if (!isdigit(line[4]))
{
ESP_LOGW(TAG,"Entered input is not a number");
return 0;
}
char temp_buf[4];
uint16_t data_to_write=0;
for(int i = 0;i <=(strlen(line)-4);i++){
temp_buf[i] = line[4+i];
}
data_to_write = atoi(temp_buf);
RGB_set_red(data_to_write);
return true;
}
return 0;
}
This function is being called when I read incomming UART data:
Code: Select all
void UART0_task(void *argument)
{
UART0_setup();
unsigned int char_received=EOF;
unsigned int char_counter=0;
char command_line[UART0_COMMAND_LINE_MAX_SIZE];
for (;;)
{
int len = uart_read_bytes(UART_NUM_0, command_line, (UART0_COMMAND_LINE_MAX_SIZE - 1), 20 / portTICK_PERIOD_MS);
if (len) {
command_line[len] = 0;
ParseSystemCmd(command_line, len); // Line is complete. Execute it!
memset(&command_line, 0, sizeof(command_line));
}
vTaskDelay(10/portTICK_PERIOD_MS);
}
Code: Select all
error: array subscript has type 'char' [-Werror=char-subscripts]
Code: Select all
if (!isdigit(line[4]))
{
ESP_LOGW(TAG,"Entered input is not a number");
return 0;
}
red:50 is valid
red:x1 is not valid