dtinfo/DtSR: coverity CID 88552; memory corruption
authorJon Trulson <jon@radscan.com>
Sat, 31 Mar 2018 20:17:36 +0000 (14:17 -0600)
committerJon Trulson <jon@radscan.com>
Sat, 31 Mar 2018 20:33:31 +0000 (14:33 -0600)
cde/programs/dtinfo/dtinfo/src/UAS/DtSR/DtSR_SearchResultsEntry.C
cde/programs/dtinfo/dtinfo/src/UAS/DtSR/TextParser.C
cde/programs/dtinfo/dtinfo/src/UAS/DtSR/TextParser.hh

index 748db330c073ee681d01750c86b629355e2c3cdc..d601b8de0ea1380fa953dbe2625ac63c512aea03 100644 (file)
@@ -333,7 +333,7 @@ DtSR_SearchResultsEntry::create_matches()
     DtSrHitword* kwics = NULL;
     long n_kwics = 0;
 
-    char* parseout = NULL;
+    const char* parseout = NULL;
 
     // hack! overwrite f_language, since austext's value is wrong
     // In future, the next lines should be removed.
index 000de4329d3cbfb4c25c50da6ee53c1ebc164df8..bc333fbd38079147d422aac9af84649005ebd97e 100644 (file)
@@ -41,7 +41,7 @@ using namespace std;
 #define True   1
 #endif
 
-char *
+const char *
 StringParser::brute_force(const char* text_in, int n_of_pats,
                                const char* patterns, int sensitive)
 {
@@ -238,18 +238,12 @@ StringParser::brute_force(const char* text_in, int n_of_pats,
     if (caped_text)
        delete[] caped_text;
 
-    string trunstr = text_run.str();
-    char* ret_text = (char *)trunstr.c_str();
+    static string trunstr = text_run.str();
 
-    if (ret_text == NULL)
-       return NULL;
-    else if (*ret_text == '\0') {
-       delete[] ret_text;
-       return NULL;
-    }
-    else
-       return ret_text;
+    if (!trunstr.size())
+        return NULL;
 
+    return trunstr.c_str();
 }
 
 const char *
@@ -332,16 +326,12 @@ StringParser::project_textrun(const char* org_textrun)
 const char *
 StringParser::hilite(const char* text, int n, const char* pats)
 {
-    char* textrun = brute_force(text, n, pats);
+    const char* textrun = brute_force(text, n, pats);
 
     if (textrun == NULL)
        return NULL;
 
-    delete[] textrun;
-
-    const char* prjed_textrun = project_textrun(textrun);
-
-    return prjed_textrun;
+    return project_textrun(textrun);
 }
 
 
index 1997b1882844a0b56e1b09585f2b9f2db1e0233a..f94928ea82eae2fd99fc221f98597105c5ae7bd7 100644 (file)
@@ -12,7 +12,7 @@ public:
   static const char *
        hilite(const char* text, int n, const char* pats);
 
-  static char *
+  static const char *
        brute_force(const char* text, int, const char* pats, int sensitive = 0);
 
   static const char *