tools: Fix static analysis warnings
authorBrian Gix <brian.gix@intel.com>
Fri, 22 Jan 2021 19:40:14 +0000 (11:40 -0800)
committerAyush Garg <ayush.garg@samsung.com>
Fri, 11 Mar 2022 13:38:34 +0000 (19:08 +0530)
Usage of potentially NULL pointers

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
tools/btmgmt.c

index 3d1a604..51a5143 100755 (executable)
@@ -4913,6 +4913,12 @@ static void cmd_advmon_add_pattern(int argc, char **argv)
 
        cp_len = sizeof(*cp) + argc * sizeof(struct mgmt_adv_pattern);
        cp = malloc0(cp_len);
+       if (!cp) {
+               error("Failed to alloc patterns.");
+               success = false;
+               goto done;
+       }
+
        cp->pattern_count = argc;
 
        for (i = 0; i < argc; i++) {
@@ -4988,6 +4994,12 @@ static void cmd_advmon_add_pattern_rssi(int argc, char **argv)
 
        cp_len = sizeof(*cp) + argc * sizeof(struct mgmt_adv_pattern);
        cp = malloc0(cp_len);
+       if (!cp) {
+               error("Failed to alloc patterns.");
+               success = false;
+               goto done;
+       }
+
        cp->pattern_count = argc;
        cp->rssi.high_threshold = rssi_high;
        cp->rssi.low_threshold = rssi_low;