Mesh: Fix model message execution 19/242819/1
authorAbhay Agarwal <ay.agarwal@samsung.com>
Tue, 1 Sep 2020 05:33:52 +0000 (11:03 +0530)
committerAbhay Agarwal <ay.agarwal@samsung.com>
Tue, 1 Sep 2020 05:34:49 +0000 (11:04 +0530)
Change-Id: I5ed5de49eb724357cbc3d2ccbedceaa7bfbeebac
Signed-off-by: Abhay Agarwal <ay.agarwal@samsung.com>
bt-service/services/mesh/bt-service-mesh-model.c

index 1e191b3..f341f0c 100644 (file)
@@ -365,6 +365,7 @@ int _bt_mesh_model_execute_msg(const char *app_cred, const char *sender,
        uint16_t appkey_idx;
        oal_uuid_t net_uuid;
        uint16_t data_len;
+       uint16_t msg_hex_len = 0;
        uint32_t opcode = 0;
        uint8_t buffer[MESH_CONFIG_BUFFER_MAX_LEN];
        uint8_t msg[BLUETOOTH_MESH_MODEL_MSG_LENGTH_MAX + 1];
@@ -395,17 +396,17 @@ int _bt_mesh_model_execute_msg(const char *app_cred, const char *sender,
                req->opcode, req->msg_len);
        if (req->msg_len > 0) {
                /* Convert Mesh msg to hex*/
-               BT_DBG("Mesh: Model string msg opcode: 0x%2.2X msg_len: %zd, msg: %s",
-                       req->opcode, strlen(req->msg), req->msg);
-               _bt_mesh_util_convert_string_to_hex(req->msg, strlen(req->msg), msg, (req->msg_len)/2);
+               BT_DBG("Mesh: Model string msg_len: %zd, msg: %s", strlen(req->msg), req->msg);
+               msg_hex_len = req->msg_len/2;
+               _bt_mesh_util_convert_string_to_hex(req->msg, strlen(req->msg), msg, msg_hex_len);
 
-               for (int msg_idx = 0; msg_idx < (req->msg_len)/2; msg_idx++)
+               for (int msg_idx = 0; msg_idx < msg_hex_len; msg_idx++)
                        BT_DBG("Mesh: Model hex msg[%d]: msg: 0x%2.2X", msg_idx, msg[msg_idx]);
 
                /* Append model msg */
-               if (req->msg_len > 0) {
-                       memcpy(buffer + data_len, msg, req->msg_len);
-                       data_len += req->msg_len;
+               if (msg_hex_len > 0) {
+                       memcpy(buffer + data_len, msg, msg_hex_len);
+                       data_len += msg_hex_len;
                }
        }