Skip to content

Commit bbe6a1a

Browse files
committed
CPP: Additional test case.
1 parent 5c855fc commit bbe6a1a

File tree

1 file changed

+12
-0
lines changed
  • cpp/ql/test/query-tests/Security/CWE/CWE-131/semmle/NoSpaceForZeroTerminator

1 file changed

+12
-0
lines changed

cpp/ql/test/query-tests/Security/CWE/CWE-131/semmle/NoSpaceForZeroTerminator/test2.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,16 @@ namespace std
1414
template <class T> class allocator {
1515
public:
1616
allocator() throw();
17+
typedef size_t size_type;
1718
};
1819

1920
template<class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> >
2021
class basic_string {
2122
public:
23+
typedef typename Allocator::size_type size_type;
2224
explicit basic_string(const Allocator& a = Allocator());
2325
basic_string(const charT* s, const Allocator& a = Allocator());
26+
basic_string(const charT* s, size_type n, const Allocator& a = Allocator());
2427

2528
const charT* c_str() const;
2629
};
@@ -36,3 +39,12 @@ void bad1(char *str) {
3639
std::string str2(buffer);
3740
free(buffer);
3841
}
42+
43+
void good1(char *str) {
44+
// GOOD --- copy does not overrun due to size limit
45+
char *buffer = (char *)malloc(strlen(str));
46+
std::string str2(buffer, strlen(str));
47+
free(buffer);
48+
}
49+
50+

0 commit comments

Comments
 (0)