Code: Select all
regex_t ledRegex;
regcomp(&ledRegex, "^/led/ch/([0-9]+)/([a-z]+)", 0);
regmatch_t match[3];
if (regexec(&ledRegex, topic, 2, NULL, 0) == 0)
{
char* p1 = strndup(event->topic + match[1].rm_so, match[1].rm_eo - match[1].rm_so);
char* p2 = strndup(event->topic + match[2].rm_so, match[2].rm_eo - match[2].rm_so);
printf("LED topic parsed: ch=%s cmd=%s\n", p1, p2);
//uint16_t num = strtol(data, NULL, 10);
free(p1);
free(p2);
}
error: 'match[1].rm_so' may be used uninitialized in this function [-Werror=maybe-uninitialized]
It's repeated for every access of that structure.
Should I stop regarding compiler warnings? In the past 15 years of coding in C# I managed to resolve all warnings, many of them pointed me to real problems and needed fixing. Not sure how C handles this.
I'm using VSCode and the esp-idf extension.