Improve librarys config of substr to improve checking cases in issue 8021 (#2338)

This commit is contained in:
Paul Fultz II 2019-11-08 01:02:33 -06:00 committed by Daniel Marjamäki
parent c358688c68
commit 650408a210
2 changed files with 35 additions and 1 deletions

View File

@ -6655,8 +6655,33 @@ The obsolete function 'gets' is called. With 'gets' you'll get a buffer overrun
<returnValue type="std::size_t"/>
<noreturn>false</noreturn>
</function>
<function name="std::string::substr,std::wstring::substr,std::basic_string::substr">
<function name="std::string::substr">
<use-retval/>
<returnValue type="std::string"/>
<noreturn>false</noreturn>
<arg nr="1" default="0" direction="in">
<not-uninit/>
<valid>0:</valid>
</arg>
<arg nr="2" default="0" direction="in">
<not-uninit/>
</arg>
</function>
<function name="std::wstring::substr">
<use-retval/>
<returnValue type="std::wstring"/>
<noreturn>false</noreturn>
<arg nr="1" default="0" direction="in">
<not-uninit/>
<valid>0:</valid>
</arg>
<arg nr="2" default="0" direction="in">
<not-uninit/>
</arg>
</function>
<function name="std::basic_string::substr">
<use-retval/>
<returnValue type="std::basic_string"/>
<noreturn>false</noreturn>
<arg nr="1" default="0" direction="in">
<not-uninit/>

View File

@ -2452,6 +2452,15 @@ private:
ASSERT_EQUALS(
"[test.cpp:3] -> [test.cpp:4]: (error) Using pointer to temporary.\n",
errout.str());
check("auto f(std::string s) {\n"
" const char *x = s.substr(1,2).c_str();\n"
" auto i = s.substr(4,5).begin();\n"
" return *i;\n"
"}\n");
ASSERT_EQUALS(
"[test.cpp:3] -> [test.cpp:4]: (error) Using iterator to temporary.\n",
errout.str());
}
void invalidLifetime() {