From 9a04fa4ff9c0ae3421496e96f6c23e0bf2e7db82 Mon Sep 17 00:00:00 2001 From: Dimitri van Heesch Date: Mon, 30 Mar 2020 20:03:16 +0200 Subject: Fixed issue creating std::string from null pointer --- qtools/qcstring.h | 5 +++++ src/formula.cpp | 10 +++++----- src/linkedmap.h | 6 +++--- src/pre.l | 20 ++++++++++---------- src/section.h | 2 +- 5 files changed, 24 insertions(+), 19 deletions(-) diff --git a/qtools/qcstring.h b/qtools/qcstring.h index ee3b82c..ec57f17 100644 --- a/qtools/qcstring.h +++ b/qtools/qcstring.h @@ -807,4 +807,9 @@ inline const char *qPrint(const QCString &s) if (!s.isEmpty()) return s.data(); else return ""; } +inline std::string toStdString(const QCString &s) +{ + if (!s.isEmpty()) return std::string(s.data()); else return std::string(); +} + #endif // QCSTRING_H diff --git a/src/formula.cpp b/src/formula.cpp index ac25cfb..8d1b0c0 100644 --- a/src/formula.cpp +++ b/src/formula.cpp @@ -3,8 +3,8 @@ * Copyright (C) 1997-2020 by Dimitri van Heesch. * * Permission to use, copy, modify, and distribute this software and its - * documentation under the terms of the GNU General Public License is hereby - * granted. No representations are made about the suitability of this software + * documentation under the terms of the GNU General Public License is hereby + * granted. No representations are made about the suitability of this software * for any purpose. It is provided "as is" without express or implied warranty. * See the GNU General Public License for more details. * @@ -181,7 +181,7 @@ void FormulaManager::generateImages(const char *path,Format format,HighDPI hd) c copyFile(macroFile,stripMacroFile); t << "\\input{" << stripMacroFile << "}" << endl; } - t << "\\pagestyle{empty}" << endl; + t << "\\pagestyle{empty}" << endl; t << "\\begin{document}" << endl; for (int i=0; i<(int)p->formulas.size(); i++) { @@ -429,7 +429,7 @@ void FormulaManager::generateImages(const char *path,Format format,HighDPI hd) c // remove the latex file itself if (RM_TMP_FILES && !formulaError) thisDir.remove("_formulas.tex"); - // write/update the formula repository so we know what text the + // write/update the formula repository so we know what text the // generated images represent (we use this next time to avoid regeneration // of the images, and to avoid forcing the user to delete all images in order // to let a browser refresh the images). @@ -461,7 +461,7 @@ void FormulaManager::clear() int FormulaManager::addFormula(const char *formulaText) { - std::string key = std::string(formulaText); + std::string key = toStdString(formulaText); auto it = p->formulaMap.find(key); if (it!=p->formulaMap.end()) // already stored { diff --git a/src/linkedmap.h b/src/linkedmap.h index 76d906d..3abc069 100644 --- a/src/linkedmap.h +++ b/src/linkedmap.h @@ -3,8 +3,8 @@ * Copyright (C) 1997-2020 by Dimitri van Heesch. * * Permission to use, copy, modify, and distribute this software and its - * documentation under the terms of the GNU General Public License is hereby - * granted. No representations are made about the suitability of this software + * documentation under the terms of the GNU General Public License is hereby + * granted. No representations are made about the suitability of this software * for any purpose. It is provided "as is" without express or implied warranty. * See the GNU General Public License for more details. * @@ -58,7 +58,7 @@ class LinkedMap { Ptr ptr = std::make_unique(key,std::forward(args)...); result = ptr.get(); - m_lookup.insert({std::string(key),result}); + m_lookup.insert({key ? std::string(key) : std::string(),result}); m_entries.push_back(std::move(ptr)); } return result; diff --git a/src/pre.l b/src/pre.l index f955cc4..06d79cc 100644 --- a/src/pre.l +++ b/src/pre.l @@ -124,7 +124,7 @@ class DefineManager { m_defines.erase(it); } - m_defines.insert(std::make_pair(std::string(def->name.data()),std::move(def))); + m_defines.insert(std::make_pair(toStdString(def->name),std::move(def))); } /** Adds an include file for this file * @param fileName The name of the include file @@ -167,7 +167,7 @@ class DefineManager if (it==m_fileMap.end()) { //printf("New file!\n"); - m_fileMap.emplace(std::string(fileName),std::make_unique(this)); + m_fileMap.emplace(toStdString(fileName),std::make_unique(this)); } } /** Ends the context started with startContext() freeing any @@ -191,7 +191,7 @@ class DefineManager if (it==m_fileMap.end()) { //printf("New file!\n"); - m_fileMap.emplace(std::string(fileName),std::make_unique(this)); + m_fileMap.emplace(toStdString(fileName),std::make_unique(this)); } else { @@ -217,7 +217,7 @@ class DefineManager { auto ptr = std::make_unique(this); ptr->addDefine(std::move(def)); - m_fileMap.emplace(std::string(fileName),std::move(ptr)); + m_fileMap.emplace(toStdString(fileName),std::move(ptr)); } else { @@ -238,7 +238,7 @@ class DefineManager { auto ptr = std::make_unique(this); ptr->addInclude(toFileName); - m_fileMap.emplace(std::string(fromFileName),std::move(ptr)); + m_fileMap.emplace(toStdString(fromFileName),std::move(ptr)); } else { @@ -1186,7 +1186,7 @@ CHARLIT (("'"\\[0-7]{1,3}"'")|("'"\\."'")|("'"[^'\\\n]{1,4}"'")) } argName = argName.stripWhiteSpace(); yyextra->defArgsStr+=yytext; - yyextra->argMap.emplace(std::string(argName.data()),yyextra->defArgs); + yyextra->argMap.emplace(toStdString(argName),yyextra->defArgs); yyextra->defArgs++; } /* @@ -2145,7 +2145,7 @@ static bool replaceFunctionMacro(yyscan_t yyscanner,const QCString &expr,QCStrin argKey.sprintf("@%d",argCount++); // key name arg=arg.stripWhiteSpace(); // add argument to the lookup table - argTable.emplace(argKey.data(), arg.data()); + argTable.emplace(toStdString(argKey), toStdString(arg)); arg.resize(0); if (c==')') // end of the argument list { @@ -2462,9 +2462,9 @@ static bool expandExpression(yyscan_t yyscanner,QCString &expr,QCString *rest,in bool expanded=false; if (def && !def->nonRecursive) { - state->expandedDict.emplace(macroName.data(),def); + state->expandedDict.emplace(toStdString(macroName),def); expanded = expandExpression(yyscanner,resultExpr,&restExpr,0,level+1); - state->expandedDict.erase(macroName.data()); + state->expandedDict.erase(toStdString(macroName)); } if (expanded) { @@ -3215,7 +3215,7 @@ static void initPredefined(yyscan_t yyscanner,const char *fileName) { if (l>0) // see bug375037 { - argMap.emplace(ds.mid(pi,l).data(),count); + argMap.emplace(toStdString(ds.mid(pi,l)),count); count++; i=pi+l; } diff --git a/src/section.h b/src/section.h index ce778b9..cf453bc 100644 --- a/src/section.h +++ b/src/section.h @@ -109,7 +109,7 @@ class SectionRefs //! Adds a non-owning section reference. void add(const SectionInfo *si) { - m_lookup.insert({std::string(si->label()),si}); + m_lookup.insert({toStdString(si->label()),si}); m_entries.push_back(si); } -- cgit v0.12