From 8862366f00c3a1729c5728bd4f48005e0f96023f Mon Sep 17 00:00:00 2001 From: Jon Trulson Date: Sat, 31 Mar 2018 14:07:28 -0600 Subject: [PATCH] dtinfo/TextParser.C: coverity CID 89054; mem corruption --- cde/programs/dtinfo/dtinfo/src/UAS/DtSR/TextParser.C | 11 ++++++----- cde/programs/dtinfo/dtinfo/src/UAS/DtSR/TextParser.hh | 4 ++-- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/cde/programs/dtinfo/dtinfo/src/UAS/DtSR/TextParser.C b/cde/programs/dtinfo/dtinfo/src/UAS/DtSR/TextParser.C index 9c02b128..000de432 100644 --- a/cde/programs/dtinfo/dtinfo/src/UAS/DtSR/TextParser.C +++ b/cde/programs/dtinfo/dtinfo/src/UAS/DtSR/TextParser.C @@ -252,7 +252,7 @@ StringParser::brute_force(const char* text_in, int n_of_pats, } -char * +const char * StringParser::project_textrun(const char* org_textrun) { if (org_textrun == NULL || *org_textrun == '\0') @@ -325,11 +325,11 @@ StringParser::project_textrun(const char* org_textrun) ret_text << off << '\t' << len << '\n' << '\0'; - string rettstr = ret_text.str(); - return (char *)rettstr.c_str(); + static string rettstr = ret_text.str(); + return rettstr.c_str(); } -char * +const char * StringParser::hilite(const char* text, int n, const char* pats) { char* textrun = brute_force(text, n, pats); @@ -337,9 +337,10 @@ StringParser::hilite(const char* text, int n, const char* pats) if (textrun == NULL) return NULL; - char* prjed_textrun = project_textrun(textrun); delete[] textrun; + const char* prjed_textrun = project_textrun(textrun); + return prjed_textrun; } diff --git a/cde/programs/dtinfo/dtinfo/src/UAS/DtSR/TextParser.hh b/cde/programs/dtinfo/dtinfo/src/UAS/DtSR/TextParser.hh index 837f3c36..1997b188 100644 --- a/cde/programs/dtinfo/dtinfo/src/UAS/DtSR/TextParser.hh +++ b/cde/programs/dtinfo/dtinfo/src/UAS/DtSR/TextParser.hh @@ -9,13 +9,13 @@ class StringParser { public: - static char * + static const char * hilite(const char* text, int n, const char* pats); static char * brute_force(const char* text, int, const char* pats, int sensitive = 0); - static char * + static const char * project_textrun(const char *); }; -- 2.25.1