mesh: Fix build error
authorLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
Tue, 13 Jun 2023 20:28:47 +0000 (13:28 -0700)
committerAyush Garg <ayush.garg@samsung.com>
Fri, 5 Jan 2024 13:34:03 +0000 (19:04 +0530)
This fixes the following error:

In function ‘get_composition’,
    inlined from ‘cfg_srv_pkt’ at mesh/cfgmod-server.c:801:8:
mesh/cfgmod-server.c:758:9: error: ‘comp’ may be used
uninitialized [-Werror=maybe-uninitialized]
  758 |         memcpy(buf, comp, len);
      |         ^~~~~~~~~~~~~~~~~~~~~~
mesh/cfgmod-server.c: In function ‘cfg_srv_pkt’:
mesh/cfgmod-server.c:739:24: note: ‘comp’ was declared here
  739 |         const uint8_t *comp;
      |                        ^~~~

mesh/cfgmod-server.c

index 3d7efc4..f64566d 100644 (file)
@@ -736,7 +736,7 @@ static uint16_t cfg_net_tx_msg(struct mesh_node *node, const uint8_t *pkt,
 static uint16_t get_composition(struct mesh_node *node, uint8_t page,
                                                                uint8_t *buf)
 {
-       const uint8_t *comp;
+       const uint8_t *comp = NULL;
        uint16_t len = 0;
        size_t i;
 
@@ -751,7 +751,7 @@ static uint16_t get_composition(struct mesh_node *node, uint8_t page,
                        break;
        }
 
-       if (!len)
+       if (!len || !comp)
                return 0;
 
        *buf++ = page;