Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[mdns]: Fixes clang-tidy warnings #732

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 22 additions & 16 deletions components/mdns/mdns.c
Original file line number Diff line number Diff line change
Expand Up @@ -253,12 +253,13 @@ static char *_mdns_mangle_name(char *in)
}
sprintf(ret, "%s-2", in);
} else {
ret = malloc(strlen(in) + 2); //one extra byte in case 9-10 or 99-100 etc
size_t in_len = strlen(in);
ret = malloc(in_len + 2); //one extra byte in case 9-10 or 99-100 etc
if (ret == NULL) {
HOOK_MALLOC_FAILED;
return NULL;
}
strcpy(ret, in);
memcpy(ret, in, in_len);
int baseLen = p - in; //length of 'bla' in 'bla-123'
//overwrite suffix with new suffix
sprintf(ret + baseLen, "-%d", suffix + 1);
Expand Down Expand Up @@ -1811,7 +1812,6 @@ static bool _mdns_create_answer_from_service(mdns_tx_packet_t *packet, mdns_serv
return false;
}
} else if (question->type == MDNS_TYPE_SDPTR) {
shared = true;
if (!_mdns_alloc_answer(&packet->answers, MDNS_TYPE_SDPTR, service, NULL, false, false)) {
return false;
}
Expand Down Expand Up @@ -2355,6 +2355,11 @@ static void _mdns_restart_pcb(mdns_if_t tcpip_if, mdns_ip_protocol_t ip_protocol
srv_count++;
a = a->next;
}
if (srv_count == 0) {
// proble only IP
_mdns_init_pcb_probe(tcpip_if, ip_protocol, NULL, 0, true);
return;
}
mdns_srv_item_t *services[srv_count];
size_t i = 0;
a = _mdns_server->services;
Expand Down Expand Up @@ -2555,6 +2560,10 @@ static void _mdns_restart_all_pcbs(void)
srv_count++;
a = a->next;
}
if (srv_count == 0) {
_mdns_probe_all_pcbs(NULL, 0, true, true);
return;
}
mdns_srv_item_t *services[srv_count];
size_t l = 0;
a = _mdns_server->services;
Expand Down Expand Up @@ -2898,11 +2907,12 @@ static int _mdns_check_srv_collision(mdns_service_t *service, uint16_t priority,
static int _mdns_check_txt_collision(mdns_service_t *service, const uint8_t *data, size_t len)
{
size_t data_len = 0;
if (len == 1 && service->txt) {
if (len <= 1 && service->txt) { // len==0 means incorrect packet (and handled by the packet parser)
// but handled here again to fix clang-tidy warning on VLA "uint8_t our[0];"
return -1;//we win
} else if (len > 1 && !service->txt) {
return 1;//they win
} else if (len == 1 && !service->txt) {
} else if (len <= 1 && !service->txt) {
return 0;//same
}

Expand Down Expand Up @@ -3788,7 +3798,7 @@ void mdns_parse_packet(mdns_rx_packet_t *packet)
mdns_class &= 0x7FFF;

content = data_ptr + data_len;
if (content > (data + len)) {
if (content > (data + len) || data_len == 0) {
goto clear_rx_packet;
}

Expand Down Expand Up @@ -4271,15 +4281,10 @@ void mdns_parse_packet(mdns_rx_packet_t *packet)
free(record);
}
free(parsed_packet);
if (browse_result_instance) {
free(browse_result_instance);
}
if (browse_result_service) {
free(browse_result_service);
}
if (browse_result_proto) {
free(browse_result_proto);
}
free(browse_result_instance);
free(browse_result_service);
free(browse_result_proto);
free(out_sync_browse);
}

/**
Expand Down Expand Up @@ -5346,7 +5351,8 @@ static void _mdns_service_task(void *pvParameters)
for (;;) {
if (_mdns_server && _mdns_server->action_queue) {
if (xQueueReceive(_mdns_server->action_queue, &a, portMAX_DELAY) == pdTRUE) {
if (a && a->type == ACTION_TASK_STOP) {
assert(a);
if (a->type == ACTION_TASK_STOP) {
break;
}
MDNS_SERVICE_LOCK();
Expand Down
Loading