mirror of
https://github.com/github/codeql.git
synced 2025-12-22 11:46:32 +01:00
CPP: Add a test case involving the std::string constructor.
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
| test2.cpp:35:28:35:33 | call to malloc | This allocation does not include space to null-terminate the string. |
|
||||||
| test.c:16:20:16:25 | call to malloc | This allocation does not include space to null-terminate the string. |
|
| test.c:16:20:16:25 | call to malloc | This allocation does not include space to null-terminate the string. |
|
||||||
| test.c:32:20:32:25 | call to malloc | This allocation does not include space to null-terminate the string. |
|
| test.c:32:20:32:25 | call to malloc | This allocation does not include space to null-terminate the string. |
|
||||||
| test.c:49:20:49:25 | call to malloc | This allocation does not include space to null-terminate the string. |
|
| test.c:49:20:49:25 | call to malloc | This allocation does not include space to null-terminate the string. |
|
||||||
|
|||||||
@@ -0,0 +1,38 @@
|
|||||||
|
|
||||||
|
///// Library functions //////
|
||||||
|
|
||||||
|
typedef unsigned long size_t;
|
||||||
|
|
||||||
|
void *malloc(size_t size);
|
||||||
|
void free(void *ptr);
|
||||||
|
size_t strlen(const char *s);
|
||||||
|
|
||||||
|
namespace std
|
||||||
|
{
|
||||||
|
template<class charT> struct char_traits;
|
||||||
|
|
||||||
|
template <class T> class allocator {
|
||||||
|
public:
|
||||||
|
allocator() throw();
|
||||||
|
};
|
||||||
|
|
||||||
|
template<class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> >
|
||||||
|
class basic_string {
|
||||||
|
public:
|
||||||
|
explicit basic_string(const Allocator& a = Allocator());
|
||||||
|
basic_string(const charT* s, const Allocator& a = Allocator());
|
||||||
|
|
||||||
|
const charT* c_str() const;
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef basic_string<char> string;
|
||||||
|
}
|
||||||
|
|
||||||
|
//// Test code /////
|
||||||
|
|
||||||
|
void bad1(char *str) {
|
||||||
|
// BAD -- Not allocating space for '\0' terminator
|
||||||
|
char *buffer = (char *)malloc(strlen(str));
|
||||||
|
std::string str2(buffer);
|
||||||
|
free(buffer);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user