From 76073e6e013031b84facd6a369ebec381669130d Mon Sep 17 00:00:00 2001
From: Jasper Verschueren <jasper.verschueren@biamp.com>
Date: Mon, 11 May 2020 15:28:09 +0200
Subject: [PATCH] mdns: fixes mixed usage of signed and unsigned for same

The slot variable was changed to u8_t but not everywhere.
s8_t is still used in some places, this patch changes that and
now only u8_t is used.
---
 src/apps/mdns/mdns.c         | 23 ++++++++++++-----------
 src/include/lwip/apps/mdns.h |  6 +++---
 2 files changed, 15 insertions(+), 14 deletions(-)

diff --git a/src/apps/mdns/mdns.c b/src/apps/mdns/mdns.c
index 36238570..65d8aade 100644
--- a/src/apps/mdns/mdns.c
+++ b/src/apps/mdns/mdns.c
@@ -1771,10 +1771,11 @@ mdns_conflict_save_time(struct netif *netif)
  *  - Let the user know there is a conflict.
  *
  * @param netif network interface on which the conflict occurred.
- * @param slot service index +1 on which the conflict occurred (0 indicate hostname conflict).
+ * @param slot  The service slot number returned by mdns_resp_add_service
+ *              (0 indicates hostname conflict).
  */
 static void
-mdns_probe_conflict(struct netif *netif, s8_t slot)
+mdns_probe_conflict(struct netif *netif, u8_t slot)
 {
   /* Increase the number of conflicts occurred and check rate limiting */
   mdns_conflict_save_time(netif);
@@ -2495,9 +2496,9 @@ mdns_resp_rename_netif(struct netif *netif, const char *hostname)
  * @param txt_fn Callback to get TXT data. Will be called each time a TXT reply is created to
  *               allow dynamic replies.
  * @param txt_data Userdata pointer for txt_fn
- * @return service_id if the service was added to the netif, an err_t otherwise
+ * @return service slot number if the service was added to the netif, MDNS_MAX_SERVICES otherwise
  */
-s8_t
+u8_t
 mdns_resp_add_service(struct netif *netif, const char *name, const char *service, enum mdns_sd_proto proto, u16_t port, service_get_txt_fn_t txt_fn, void *txt_data)
 {
   u8_t slot;
@@ -2507,21 +2508,21 @@ mdns_resp_add_service(struct netif *netif, const char *name, const char *service
   LWIP_ASSERT_CORE_LOCKED();
   LWIP_ASSERT("mdns_resp_add_service: netif != NULL", netif);
   mdns = NETIF_TO_HOST(netif);
-  LWIP_ERROR("mdns_resp_add_service: Not an mdns netif", (mdns != NULL), return ERR_VAL);
+  LWIP_ERROR("mdns_resp_add_service: Not an mdns netif", (mdns != NULL), return MDNS_MAX_SERVICES);
 
-  LWIP_ERROR("mdns_resp_add_service: Name too long", (strlen(name) <= MDNS_LABEL_MAXLEN), return ERR_VAL);
-  LWIP_ERROR("mdns_resp_add_service: Service too long", (strlen(service) <= MDNS_LABEL_MAXLEN), return ERR_VAL);
-  LWIP_ERROR("mdns_resp_add_service: Bad proto (need TCP or UDP)", (proto == DNSSD_PROTO_TCP || proto == DNSSD_PROTO_UDP), return ERR_VAL);
+  LWIP_ERROR("mdns_resp_add_service: Name too long", (strlen(name) <= MDNS_LABEL_MAXLEN), return MDNS_MAX_SERVICES);
+  LWIP_ERROR("mdns_resp_add_service: Service too long", (strlen(service) <= MDNS_LABEL_MAXLEN), return MDNS_MAX_SERVICES);
+  LWIP_ERROR("mdns_resp_add_service: Bad proto (need TCP or UDP)", (proto == DNSSD_PROTO_TCP || proto == DNSSD_PROTO_UDP), return MDNS_MAX_SERVICES);
 
   for (slot = 0; slot < MDNS_MAX_SERVICES; slot++) {
     if (mdns->services[slot] == NULL) {
       break;
     }
   }
-  LWIP_ERROR("mdns_resp_add_service: Service list full (increase MDNS_MAX_SERVICES)", (slot < MDNS_MAX_SERVICES), return ERR_MEM);
+  LWIP_ERROR("mdns_resp_add_service: Service list full (increase MDNS_MAX_SERVICES)", (slot < MDNS_MAX_SERVICES), return MDNS_MAX_SERVICES);
 
   srv = (struct mdns_service *)mem_calloc(1, sizeof(struct mdns_service));
-  LWIP_ERROR("mdns_resp_add_service: Alloc failed", (srv != NULL), return ERR_MEM);
+  LWIP_ERROR("mdns_resp_add_service: Alloc failed", (srv != NULL), return MDNS_MAX_SERVICES);
 
   MEMCPY(&srv->name, name, LWIP_MIN(MDNS_LABEL_MAXLEN, strlen(name)));
   MEMCPY(&srv->service, service, LWIP_MIN(MDNS_LABEL_MAXLEN, strlen(service)));
@@ -2825,7 +2826,7 @@ mdns_resp_init(void)
  * @param netif Network interface.
  * @param slot Service index.
  */
-void *mdns_get_service_txt_userdata(struct netif *netif, s8_t slot)
+void *mdns_get_service_txt_userdata(struct netif *netif, u8_t slot)
 {
   struct mdns_host *mdns = NETIF_TO_HOST(netif);
   struct mdns_service *s;
diff --git a/src/include/lwip/apps/mdns.h b/src/include/lwip/apps/mdns.h
index e8c1ef9e..e00814a7 100644
--- a/src/include/lwip/apps/mdns.h
+++ b/src/include/lwip/apps/mdns.h
@@ -99,9 +99,9 @@ typedef void (*service_get_txt_fn_t)(struct mdns_service *service, void *txt_use
  * uniqueness, called with result MDNS_PROBING_SUCCESSFUL if no other node claimed
  * use for the name for the netif or a service and is safe to use, or MDNS_PROBING_CONFLICT
  * if another node is already using it and mdns is disabled on this interface */
-typedef void (*mdns_name_result_cb_t)(struct netif* netif, u8_t result, s8_t slot);
+typedef void (*mdns_name_result_cb_t)(struct netif* netif, u8_t result, u8_t slot);
 
-void *mdns_get_service_txt_userdata(struct netif *netif, s8_t slot);
+void *mdns_get_service_txt_userdata(struct netif *netif, u8_t slot);
 
 void mdns_resp_init(void);
 
@@ -111,7 +111,7 @@ err_t mdns_resp_add_netif(struct netif *netif, const char *hostname);
 err_t mdns_resp_remove_netif(struct netif *netif);
 err_t mdns_resp_rename_netif(struct netif *netif, const char *hostname);
 
-s8_t  mdns_resp_add_service(struct netif *netif, const char *name, const char *service, enum mdns_sd_proto proto, u16_t port, service_get_txt_fn_t txt_fn, void *txt_userdata);
+u8_t  mdns_resp_add_service(struct netif *netif, const char *name, const char *service, enum mdns_sd_proto proto, u16_t port, service_get_txt_fn_t txt_fn, void *txt_userdata);
 err_t mdns_resp_del_service(struct netif *netif, u8_t slot);
 err_t mdns_resp_rename_service(struct netif *netif, u8_t slot, const char *name);
 
-- 
2.17.1

