dtinfo: fix coverity issues related to null checks after dereference
authorPeter Howkins <flibble@users.sf.net>
Wed, 4 Apr 2018 21:42:06 +0000 (22:42 +0100)
committerPeter Howkins <flibble@users.sf.net>
Wed, 4 Apr 2018 21:42:06 +0000 (22:42 +0100)
cde/programs/dtinfo/DtMmdb/api/base.C
cde/programs/dtinfo/DtMmdb/api/info_base.C
cde/programs/dtinfo/dtinfo/src/Basic/NodeViewInfo.C
cde/programs/dtinfo/dtinfo/src/UAS/DtSR/DtSR_SearchEngine.C
cde/programs/dtinfo/dtinfogen/infolib/etc/AusText.C
cde/programs/dtinfo/dtinfogen/infolib/etc/dtinfogen_worker.c

index 29a9e9daac45982e113b2eb3733f8292b9872f87..a38f7ca802c327e9aa18e141c238337155ca9493 100644 (file)
@@ -70,29 +70,33 @@ base::base(object_dict* obj_dict,
    num_cset_ptrs(0), num_list_ptrs(0),
    f_obj_dict(obj_dict)
 {
-   int len = MIN(strlen(base_dir), PATHSIZ - 1);
-   if ( base_dir )
+   if ( base_dir ) {
+      int len = MIN(strlen(base_dir), PATHSIZ - 1);
       *((char *) memcpy (base_path, base_dir, len) + len) = '\0';
-   else
+   } else {
       base_path[0] = 0;
+   }
 
-   len = MIN(strlen(base_nm), PATHSIZ - 1);
-   if ( base_nm )
+   if ( base_nm ) {
+      int len = MIN(strlen(base_nm), PATHSIZ - 1);
       *((char *) memcpy (base_name, base_nm, len) + len) = '\0';
-   else
+   } else {
       base_name[0] = 0;
+   }
 
-   len = MIN(strlen(base_ds), PATHSIZ - 1);
-   if ( base_ds )
+   if ( base_ds ) {
+      int len = MIN(strlen(base_ds), PATHSIZ - 1);
       *((char *) memcpy (base_desc, base_ds, len) + len) = '\0';
-   else
+   } else {
       base_desc[0] = 0;
+   }
 
-   len = MIN(strlen(base_uid_str), UIDSIZ - 1);
-   if ( base_uid_str )
+   if ( base_uid_str ) {
+      int len = MIN(strlen(base_uid_str), UIDSIZ - 1);
       *((char *) memcpy (base_uid, base_uid_str, len) + len) = '\0';
-   else
+   } else {
       base_uid[0] = 0;
+   }
 
    if ( set_nms )
       while ( info_base_set_names[num_cset_ptrs] )
index ff503a47d0fd150293047687b0ec5ac911703a58..6d6a568c96474c1cfcdabc624a98b1d1e98a2f20 100644 (file)
@@ -72,11 +72,12 @@ debug(cerr, base_dir);
 debug(cerr, base_nm);
 debug(cerr, base_ds);
 */
-   int len = MIN(strlen(base_locale), PATHSIZ - 1);
-   if (base_locale)
+   if (base_locale) {
+     int len = MIN(strlen(base_locale), PATHSIZ - 1);
      *((char *) memcpy (info_base_locale, base_locale, len) + len) = '\0';
-   else
+   } else {
      *info_base_locale = 0;
+   }
 
    char* nm ;
    int i;
index 6a303061bfae513baef56205a8af386c51de33e4..3ec72eb0f4b9ab77153c9b76a5225d6f2d3bf1e3 100644 (file)
@@ -530,8 +530,7 @@ highlight_search_hit(_DtCvSegment* seg, unsigned int vcc, unsigned int len)
                }
                DtCvStrVcLenSync(seg);
 
-               if (sibling->handle.string.string)
-                   free (sibling->handle.string.string);
+               free (sibling->handle.string.string);
                if (sibling->client_use) {
                    delete (SegClientData*)sibling->client_use;
                    sibling->client_use = NULL;
index b2262f9cd93b512009db35b6b9b9b91b74d4e533..105e134b49f87f15ef3933be61837f97f52a1b3a 100644 (file)
@@ -129,8 +129,7 @@ build_bc_url(UAS_String bookcase_path)
     fprintf(stderr, "(DEBUG) URL=\"%s\"\n", (char*)bc_locator);
 #endif
 
-    if (bc_path)
-       free(bc_path);
+    free(bc_path);
 
     return bc_locator;
 }
index 853fd250e87312070a71b2d8dcae88bbf983a29e..108a5108b35ea46e6a899fd17d1ad7ea89e0eda3 100644 (file)
@@ -77,7 +77,7 @@ AusText::~AusText()
 {
   store->deActivateZone ( f_base );
 
-  if ( store ) { delete store; }
+  delete store;
   if ( f_search_store ) { delete f_search_store; }
 }
 
index 5af2584344b33c4890e67056feefcaadbe767736..f4328270b9ddf0557fdbcd25a4995beddc367585 100644 (file)
@@ -828,8 +828,7 @@ makeAbsPathEnv(char *var)
     snprintf(newVar, pathlen, "%s=%s", var, newPath);
     putenv(newVar);
 
-    if (newPath)
-       XtFree(newPath);
+    XtFree(newPath);
 
     return newVar;
 }