shared/gatt-client: Fix smatch warnings
authorLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
Fri, 6 Jan 2023 00:32:55 +0000 (16:32 -0800)
committerAyush Garg <ayush.garg@samsung.com>
Fri, 5 Jan 2024 10:11:34 +0000 (15:41 +0530)
This fixes the following warnings:

shared/gatt-client.c:2764:33: warning: Variable length array is used.
shared/gatt-client.c:2994:23: warning: Variable length array is used.
shared/gatt-client.c:3075:23: warning: Variable length array is used.
shared/gatt-client.c:3514:23: warning: Variable length array is used.

src/shared/gatt-client.c

index aa694a0..f0fd6bd 100644 (file)
@@ -3100,7 +3100,7 @@ unsigned int bt_gatt_client_read_multiple(struct bt_gatt_client *client,
                                        void *user_data,
                                        bt_gatt_client_destroy_func_t destroy)
 {
-       uint8_t pdu[num_handles * 2];
+       uint8_t *pdu = newa(uint8_t, num_handles * 2);
        struct request *req;
        struct read_op *op;
        uint8_t opcode;
@@ -3137,7 +3137,7 @@ unsigned int bt_gatt_client_read_multiple(struct bt_gatt_client *client,
                BT_GATT_CHRC_CLI_FEAT_EATT ? BT_ATT_OP_READ_MULT_VL_REQ :
                BT_ATT_OP_READ_MULT_REQ;
 
-       req->att_id = bt_att_send(client->att, opcode, pdu, sizeof(pdu),
+       req->att_id = bt_att_send(client->att, opcode, pdu, num_handles * 2,
                                                        read_multiple_cb, req,
                                                        request_unref);
        if (!req->att_id) {
@@ -3419,7 +3419,7 @@ unsigned int bt_gatt_client_write_without_response(
                                        uint16_t value_handle,
                                        bool signed_write,
                                        const uint8_t *value, uint16_t length) {
-       uint8_t pdu[2 + length];
+       uint8_t *pdu = newa(uint8_t, 2 + length);
        struct request *req;
        int security;
        uint8_t op;
@@ -3442,7 +3442,7 @@ unsigned int bt_gatt_client_write_without_response(
        put_le16(value_handle, pdu);
        memcpy(pdu + 2, value, length);
 
-       req->att_id = bt_att_send(client->att, op, pdu, sizeof(pdu), NULL, req,
+       req->att_id = bt_att_send(client->att, op, pdu, 2 + length, NULL, req,
                                                                request_unref);
        if (!req->att_id) {
                request_unref(req);
@@ -3500,7 +3500,7 @@ unsigned int bt_gatt_client_write_value(struct bt_gatt_client *client,
 {
        struct request *req;
        struct write_op *op;
-       uint8_t pdu[2 + length];
+       uint8_t *pdu = newa(uint8_t, 2 + length);
 
        if (!client)
                return 0;
@@ -3524,7 +3524,7 @@ unsigned int bt_gatt_client_write_value(struct bt_gatt_client *client,
        memcpy(pdu + 2, value, length);
 
        req->att_id = bt_att_send(client->att, BT_ATT_OP_WRITE_REQ,
-                                                       pdu, sizeof(pdu),
+                                                       pdu, 2 + length,
                                                        write_cb, req,
                                                        request_unref);
        if (!req->att_id) {
@@ -3939,7 +3939,7 @@ unsigned int bt_gatt_client_prepare_write(struct bt_gatt_client *client,
 {
        struct request *req;
        struct prep_write_op *op;
-       uint8_t pdu[4 + length];
+       uint8_t *pdu = newa(uint8_t, 4 + length);
 
        if (!client)
                return 0;
@@ -3998,7 +3998,7 @@ unsigned int bt_gatt_client_prepare_write(struct bt_gatt_client *client,
         * Note that request_unref will be done on write execute
         */
        req->att_id = bt_att_send(client->att, BT_ATT_OP_PREP_WRITE_REQ, pdu,
-                                       sizeof(pdu), prep_write_cb, req,
+                                       length, prep_write_cb, req,
                                        NULL);
        if (!req->att_id) {
                op->destroy = NULL;