arm_adi_v5: check for calloc() return value
authorAntonio Borneo <borneo.antonio@gmail.com>
Thu, 2 Jun 2022 09:17:49 +0000 (11:17 +0200)
committerAntonio Borneo <borneo.antonio@gmail.com>
Fri, 10 Jun 2022 21:54:55 +0000 (21:54 +0000)
In function adiv5_jim_configure() check that calloc() returns a
valid allocated memory pointer.

Change-Id: I97287e168834693900341add9d9eb9a5f38c55b4
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reported-by: Tomas Vanek <vanekt@fbl.cz>
Reviewed-on: https://review.openocd.org/c/openocd/+/7014
Tested-by: jenkins
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
src/target/arm_adi_v5.c

index 52b12cb93f1e4ef17c4f01366b2fa7668ba528ca..4d5f02b328a875a03d710c2450e101d734b3158a 100644 (file)
@@ -2044,6 +2044,10 @@ int adiv5_jim_configure(struct target *target, struct jim_getopt_info *goi)
        pc = (struct adiv5_private_config *)target->private_config;
        if (!pc) {
                pc = calloc(1, sizeof(struct adiv5_private_config));
+               if (!pc) {
+                       LOG_ERROR("Out of memory");
+                       return JIM_ERR;
+               }
                pc->ap_num = DP_APSEL_INVALID;
                target->private_config = pc;
        }