Fix coverity defect: Dereference before null check 99/261099/1 accepted/tizen/unified/20210713.053503 submit/tizen/20210712.052211
authorDongkyun Son <dongkyun.s@samsung.com>
Mon, 12 Jul 2021 04:12:08 +0000 (13:12 +0900)
committerDongkyun Son <dongkyun.s@samsung.com>
Mon, 12 Jul 2021 04:14:38 +0000 (13:14 +0900)
CID 1238715 (#1 of 1): Dereference before null check (REVERSE_INULL)

check_after_deref: Null-checking value suggests that it may be null, but it has
                   already been dereferenced on all paths leading to the check.

Change-Id: I9a8295a32fc709a9095126db6e2cf5f78cda6c9a
Signed-off-by: Dongkyun Son <dongkyun.s@samsung.com>
src/sdb.c

index 4e1e67dcf4a64889bbcbd40b1a4945c7b22b9da4..29ed3a8c6d5754c5cf3e8422d133a714c2cc8aff 100755 (executable)
--- a/src/sdb.c
+++ b/src/sdb.c
@@ -1757,17 +1757,17 @@ static void init_capabilities(void) {
                     "%s", UNKNOWN);
         E("fail to get the CPU architecture of model:%d\n", errno);
     } else {
-        // check for armv8 and 32 bit architecture, for it make the cpu arch as armv7l
-        if(!strncmp(value,"armv8",sizeof("armv8")+1) && !strncmp(arch,"32",sizeof("32")+1))
-        {
-            D("Changing cpu arch in capability from %s to %s for %s bit\n",value,"armv7l",arch);
-            snprintf(g_capabilities.cpu_arch, sizeof(g_capabilities.cpu_arch),
-                                            "%s", "armv7l");
-        } else {
-            snprintf(g_capabilities.cpu_arch, sizeof(g_capabilities.cpu_arch),
-                                "%s", value);
-        }
         if (value != NULL) {
+            // check for armv8 and 32 bit architecture, for it make the cpu arch as armv7l
+            if(!strncmp(value,"armv8",sizeof("armv8")+1) && !strncmp(arch,"32",sizeof("32")+1))
+            {
+                D("Changing cpu arch in capability from %s to %s for %s bit\n",value,"armv7l",arch);
+                snprintf(g_capabilities.cpu_arch, sizeof(g_capabilities.cpu_arch),
+                                    "%s", "armv7l");
+            } else {
+                snprintf(g_capabilities.cpu_arch, sizeof(g_capabilities.cpu_arch),
+                                    "%s", value);
+            }
             free(value);
         }
     }