diff --git a/cfg/std.cfg b/cfg/std.cfg index cd84c30c0..59673e1d4 100644 --- a/cfg/std.cfg +++ b/cfg/std.cfg @@ -6600,15 +6600,6 @@ The obsolete function 'gets' is called. With 'gets' you'll get a buffer overrun - - - - - - - - false - @@ -6676,12 +6667,6 @@ The obsolete function 'gets' is called. With 'gets' you'll get a buffer overrun - - - - - false - @@ -6969,12 +6954,6 @@ The obsolete function 'gets' is called. With 'gets' you'll get a buffer overrun 0: - - - - - false - @@ -8589,8 +8568,8 @@ initializer list (7) string& replace (const_iterator i1, const_iterator i2, init - - + + @@ -8640,7 +8619,7 @@ initializer list (7) string& replace (const_iterator i1, const_iterator i2, init - + @@ -8757,7 +8736,7 @@ initializer list (7) string& replace (const_iterator i1, const_iterator i2, init - + diff --git a/lib/library.cpp b/lib/library.cpp index 0f21a415f..dcc51f392 100644 --- a/lib/library.cpp +++ b/lib/library.cpp @@ -484,6 +484,10 @@ Library::Error Library::load(const tinyxml2::XMLDocument &doc) return Error(ErrorCode::BAD_ATTRIBUTE_VALUE, yieldName); } + const char* const returnType = functionNode->Attribute("returnType"); + if (returnType) + container.functions[functionName].returnType = returnType; + container.functions[functionName].action = action; container.functions[functionName].yield = yield; } @@ -905,6 +909,10 @@ Library::Error Library::loadFunction(const tinyxml2::XMLElement * const node, co return Error(ErrorCode::BAD_ATTRIBUTE_VALUE, yieldName); } func.containerYield = yield; + + const char* const returnType = functionnode->Attribute("returnType"); + if (returnType) + func.returnType = returnType; } else unknown_elements.insert(functionnodename); } @@ -1385,6 +1393,11 @@ const std::string& Library::returnValue(const Token *ftok) const const std::string& Library::returnValueType(const Token *ftok) const { + if (Token::simpleMatch(ftok->astParent(), ".") && ftok->astParent()->astOperand1()) { + const Token* contTok = ftok->astParent()->astOperand1(); + if (contTok->valueType() && contTok->valueType()->container) + return contTok->valueType()->container->getReturnType(ftok->str()); + } if (isNotLibraryFunction(ftok)) return emptyString; const std::map::const_iterator it = mReturnValueType.find(getFunctionName(ftok)); @@ -1479,6 +1492,12 @@ bool Library::isFunctionConst(const Token *ftok) const { if (ftok->function() && ftok->function()->isConst()) return true; + if (Token::simpleMatch(ftok->astParent(), ".")) { + using Yield = Library::Container::Yield; + const Yield yield = astContainerYield(ftok->astParent()->astOperand1()); + if (yield == Yield::EMPTY || yield == Yield::SIZE || yield == Yield::BUFFER_NT) + return true; + } if (isNotLibraryFunction(ftok)) return false; const std::unordered_map::const_iterator it = functions.find(getFunctionName(ftok)); @@ -1489,6 +1508,11 @@ bool Library::isnoreturn(const Token *ftok) const { if (ftok->function() && ftok->function()->isAttributeNoreturn()) return true; + if (Token::simpleMatch(ftok->astParent(), ".")) { + if (astContainerAction(ftok->astParent()->astOperand1()) != Library::Container::Action::NO_ACTION || + astContainerYield(ftok->astParent()->astOperand1()) != Library::Container::Yield::NO_YIELD) + return false; + } if (isNotLibraryFunction(ftok)) return false; const std::unordered_map::const_iterator it = mNoReturn.find(getFunctionName(ftok)); diff --git a/lib/library.h b/lib/library.h index 306f86ac6..cbc2e0469 100644 --- a/lib/library.h +++ b/lib/library.h @@ -249,8 +249,9 @@ public: NO_YIELD }; struct Function { - Action action; - Yield yield; + Action action = Action::NO_ACTION; + Yield yield = Yield::NO_YIELD; + std::string returnType; }; struct RangeItemRecordTypeItem { std::string name; @@ -284,6 +285,11 @@ public: return Yield::NO_YIELD; } + const std::string& getReturnType(const std::string& function) const { + auto i = functions.find(function); + return (i != functions.end()) ? i->second.returnType : emptyString; + } + static Yield yieldFrom(const std::string& yieldName); static Action actionFrom(const std::string& actionName); }; @@ -359,6 +365,7 @@ public: bool formatstr_secure; Container::Action containerAction; Container::Yield containerYield; + std::string returnType; Function() : use(false), leakignore(false),