Skip to content

Commit 33111b6

Browse files
authored
Merge pull request #498 from geoffw0/test-cleanup
CPP: Clean up some test code.
2 parents 252b756 + 342164f commit 33111b6

File tree

3 files changed

+18
-16
lines changed

3 files changed

+18
-16
lines changed

cpp/ql/test/library-tests/opts/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11

22
char *Xstrdup(const char *string);
3-
void abort();
3+
void abort(void);
44
struct FILE;
5-
char *fgets(char *str, int num, FILE *stream);
5+
char *fgets(char *s, int n, FILE *stream);
66
int ignore_return_value();
77
#define IGNORE_RETURN_VALUE() ignore_return_value()
88
void myIgnoreReturnValue();
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
| test.cpp:22:3:22:26 | return ... | Return value may contain a dangling pointer to $@. | test.cpp:21:24:21:37 | call to string | this local std::string |
2-
| test.cpp:30:3:30:44 | return ... | Return value may contain a dangling pointer to $@. | test.cpp:30:10:30:35 | call to string | this local std::string |
3-
| test.cpp:43:3:43:42 | return ... | Return value may contain a dangling pointer to $@. | test.cpp:42:22:42:35 | call to string | this local std::string |
1+
| test.cpp:24:3:24:26 | return ... | Return value may contain a dangling pointer to $@. | test.cpp:23:24:23:37 | call to basic_string | this local std::string |
2+
| test.cpp:32:3:32:44 | return ... | Return value may contain a dangling pointer to $@. | test.cpp:32:10:32:35 | call to basic_string | this local std::string |
3+
| test.cpp:45:3:45:42 | return ... | Return value may contain a dangling pointer to $@. | test.cpp:44:22:44:35 | call to basic_string | this local std::string |

cpp/ql/test/query-tests/Likely Bugs/Memory Management/ReturnCstrOfLocalStdString/test.cpp

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
1-
extern "C" {
2-
char *strdup(const char *s);
3-
void free (void* ptr);
4-
}
51

62
namespace std {
7-
// We are not allowed to include <string> in the test file,
8-
// so this is an approximation of the std::string class.
9-
class string {
10-
char* str_;
3+
template<class charT> struct char_traits;
114

5+
template <class T> class allocator {
126
public:
13-
string(const char* str) : str_(strdup(str)) {}
14-
~string() { free(str_); }
7+
allocator() throw();
8+
};
159

16-
const char* c_str() const noexcept { return str_; }
10+
template<class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> >
11+
class basic_string {
12+
public:
13+
explicit basic_string(const Allocator& a = Allocator());
14+
basic_string(const charT* s, const Allocator& a = Allocator());
15+
16+
const charT* c_str() const;
1717
};
18+
19+
typedef basic_string<char> string;
1820
}
1921

2022
const char* bad000() {

0 commit comments

Comments
 (0)