mirror of
https://github.com/github/codeql.git
synced 2026-04-26 01:05:15 +02:00
C++: Force LF for .c,.cpp,.h,.hpp
This commit is contained in:
1
cpp/ql/test/query-tests/AlertSuppression/.gitattributes
vendored
Normal file
1
cpp/ql/test/query-tests/AlertSuppression/.gitattributes
vendored
Normal file
@@ -0,0 +1 @@
|
||||
tstWindows.c eol=crlf
|
||||
@@ -1,28 +1,28 @@
|
||||
int x = 0; // lgtm
|
||||
// lgtm[js/debugger-statement]
|
||||
// lgtm[js/debugger-statement, js/invocation-of-non-function]
|
||||
// lgtm[@tag:nullness]
|
||||
// lgtm[@tag:nullness,js/debugger-statement]
|
||||
// lgtm[@expires:2017-06-11]
|
||||
// lgtm[js/invocation-of-non-function] because I know better than lgtm
|
||||
// lgtm: blah blah
|
||||
// lgtm blah blah #falsepositive
|
||||
//lgtm [js/invocation-of-non-function]
|
||||
/* lgtm */
|
||||
// lgtm[]
|
||||
// lgtmfoo
|
||||
//lgtm
|
||||
// lgtm
|
||||
// lgtm [js/debugger-statement]
|
||||
// foolgtm[js/debugger-statement]
|
||||
// foolgtm
|
||||
// foo; lgtm
|
||||
// foo; lgtm[js/debugger-statement]
|
||||
// foo lgtm
|
||||
// foo lgtm[js/debugger-statement]
|
||||
// foo lgtm bar
|
||||
// foo lgtm[js/debugger-statement] bar
|
||||
// LGTM!
|
||||
// LGTM[js/debugger-statement]
|
||||
// lgtm[js/debugger-statement] and lgtm[js/invocation-of-non-function]
|
||||
// lgtm[js/debugger-statement]; lgtm
|
||||
int x = 0; // lgtm
|
||||
// lgtm[js/debugger-statement]
|
||||
// lgtm[js/debugger-statement, js/invocation-of-non-function]
|
||||
// lgtm[@tag:nullness]
|
||||
// lgtm[@tag:nullness,js/debugger-statement]
|
||||
// lgtm[@expires:2017-06-11]
|
||||
// lgtm[js/invocation-of-non-function] because I know better than lgtm
|
||||
// lgtm: blah blah
|
||||
// lgtm blah blah #falsepositive
|
||||
//lgtm [js/invocation-of-non-function]
|
||||
/* lgtm */
|
||||
// lgtm[]
|
||||
// lgtmfoo
|
||||
//lgtm
|
||||
// lgtm
|
||||
// lgtm [js/debugger-statement]
|
||||
// foolgtm[js/debugger-statement]
|
||||
// foolgtm
|
||||
// foo; lgtm
|
||||
// foo; lgtm[js/debugger-statement]
|
||||
// foo lgtm
|
||||
// foo lgtm[js/debugger-statement]
|
||||
// foo lgtm bar
|
||||
// foo lgtm[js/debugger-statement] bar
|
||||
// LGTM!
|
||||
// LGTM[js/debugger-statement]
|
||||
// lgtm[js/debugger-statement] and lgtm[js/invocation-of-non-function]
|
||||
// lgtm[js/debugger-statement]; lgtm
|
||||
|
||||
@@ -1,33 +1,33 @@
|
||||
|
||||
int myFunction1(int x =
|
||||
102 + 102 + 102 +
|
||||
102 + 102 + 102 +
|
||||
102 + 102 + 102 +
|
||||
102 + 102 + 102 +
|
||||
102 + 102 + 102 +
|
||||
102 + 102 + 102 +
|
||||
102 + 102 + 102);
|
||||
|
||||
void myFunction2(
|
||||
int p1 = 103,
|
||||
int p2 = 103,
|
||||
int p3 = 103,
|
||||
int p4 = 103,
|
||||
int p5 = 103,
|
||||
int p6 = 103,
|
||||
int p7 = 103,
|
||||
int p8 = 103,
|
||||
int p9 = 103,
|
||||
int p10 = 103,
|
||||
int p11 = 103,
|
||||
int p12 = 103,
|
||||
int p13 = 103,
|
||||
int p14 = 103,
|
||||
int p15 = 103,
|
||||
int p16 = 103,
|
||||
int p17 = 103,
|
||||
int p18 = 103,
|
||||
int p19 = 103,
|
||||
int p20 = 103,
|
||||
int p21 = 103
|
||||
) {};
|
||||
|
||||
int myFunction1(int x =
|
||||
102 + 102 + 102 +
|
||||
102 + 102 + 102 +
|
||||
102 + 102 + 102 +
|
||||
102 + 102 + 102 +
|
||||
102 + 102 + 102 +
|
||||
102 + 102 + 102 +
|
||||
102 + 102 + 102);
|
||||
|
||||
void myFunction2(
|
||||
int p1 = 103,
|
||||
int p2 = 103,
|
||||
int p3 = 103,
|
||||
int p4 = 103,
|
||||
int p5 = 103,
|
||||
int p6 = 103,
|
||||
int p7 = 103,
|
||||
int p8 = 103,
|
||||
int p9 = 103,
|
||||
int p10 = 103,
|
||||
int p11 = 103,
|
||||
int p12 = 103,
|
||||
int p13 = 103,
|
||||
int p14 = 103,
|
||||
int p15 = 103,
|
||||
int p16 = 103,
|
||||
int p17 = 103,
|
||||
int p18 = 103,
|
||||
int p19 = 103,
|
||||
int p20 = 103,
|
||||
int p21 = 103
|
||||
) {};
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
|
||||
#include "functions.h"
|
||||
|
||||
int myFunction1(int x) {
|
||||
return x;
|
||||
}
|
||||
|
||||
void myCaller() {
|
||||
myFunction1();
|
||||
myFunction1();
|
||||
myFunction1(104);
|
||||
myFunction2(105);
|
||||
myFunction2();
|
||||
|
||||
#include "functions.h"
|
||||
|
||||
int myFunction1(int x) {
|
||||
return x;
|
||||
}
|
||||
|
||||
void myCaller() {
|
||||
myFunction1();
|
||||
myFunction1();
|
||||
myFunction1(104);
|
||||
myFunction2(105);
|
||||
myFunction2();
|
||||
}
|
||||
@@ -1,3 +1,3 @@
|
||||
// a.h
|
||||
|
||||
int my_func_a();
|
||||
// a.h
|
||||
|
||||
int my_func_a();
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
// b.h
|
||||
|
||||
int my_func_b();
|
||||
// b.h
|
||||
|
||||
int my_func_b();
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
// c.h
|
||||
|
||||
extern int my_var_c;
|
||||
// c.h
|
||||
|
||||
extern int my_var_c;
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
// d.hpp
|
||||
|
||||
class class_d;
|
||||
// d.hpp
|
||||
|
||||
class class_d;
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
// e.hpp
|
||||
|
||||
class class_e;
|
||||
// e.hpp
|
||||
|
||||
class class_e;
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
// f.fwd.hpp
|
||||
|
||||
class class_f;
|
||||
// f.fwd.hpp
|
||||
|
||||
class class_f;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
// header1.h
|
||||
|
||||
#ifndef INCLUDED_HEADER1
|
||||
#define INCLUDED_HEADER1
|
||||
|
||||
// ...
|
||||
|
||||
#endif // INCLUDED_HEADER1
|
||||
// header1.h
|
||||
|
||||
#ifndef INCLUDED_HEADER1
|
||||
#define INCLUDED_HEADER1
|
||||
|
||||
// ...
|
||||
|
||||
#endif // INCLUDED_HEADER1
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
// header2.h
|
||||
|
||||
#ifndef INCLUDED_HEADER1 // oops!
|
||||
#define INCLUDED_HEADER1
|
||||
|
||||
// ...
|
||||
|
||||
#endif // INCLUDED_HEADER1
|
||||
// header2.h
|
||||
|
||||
#ifndef INCLUDED_HEADER1 // oops!
|
||||
#define INCLUDED_HEADER1
|
||||
|
||||
// ...
|
||||
|
||||
#endif // INCLUDED_HEADER1
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
// header3.h
|
||||
|
||||
#ifndef INCLUDED_HEADER3
|
||||
#define INCLUDED_HEADER3
|
||||
|
||||
// ...
|
||||
|
||||
#ifndef INCLUDED_HEADER1 // (not an include guard)
|
||||
|
||||
#endif
|
||||
|
||||
#endif // INCLUDED_HEADER3
|
||||
// header3.h
|
||||
|
||||
#ifndef INCLUDED_HEADER3
|
||||
#define INCLUDED_HEADER3
|
||||
|
||||
// ...
|
||||
|
||||
#ifndef INCLUDED_HEADER1 // (not an include guard)
|
||||
|
||||
#endif
|
||||
|
||||
#endif // INCLUDED_HEADER3
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
// header4.h
|
||||
|
||||
#ifndef INCLUDED_HEADER4
|
||||
#define INCLUDED_HEADER4
|
||||
|
||||
// ...
|
||||
|
||||
#endif // INCLUDED_HEADER4
|
||||
// header4.h
|
||||
|
||||
#ifndef INCLUDED_HEADER4
|
||||
#define INCLUDED_HEADER4
|
||||
|
||||
// ...
|
||||
|
||||
#endif // INCLUDED_HEADER4
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
// header6.h
|
||||
|
||||
#ifndef INCLUDED_HEADER6
|
||||
#define INCLUDED_HEADER6
|
||||
|
||||
// ...
|
||||
|
||||
#endif // INCLUDED_HEADER6
|
||||
// header6.h
|
||||
|
||||
#ifndef INCLUDED_HEADER6
|
||||
#define INCLUDED_HEADER6
|
||||
|
||||
// ...
|
||||
|
||||
#endif // INCLUDED_HEADER6
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
// header7.h
|
||||
|
||||
#ifndef INCLUDED_HEADER6 // oops!
|
||||
#define INCLUDED_HEADER6(x) (x)
|
||||
|
||||
// ...
|
||||
|
||||
#endif // INCLUDED_HEADER6
|
||||
// header7.h
|
||||
|
||||
#ifndef INCLUDED_HEADER6 // oops!
|
||||
#define INCLUDED_HEADER6(x) (x)
|
||||
|
||||
// ...
|
||||
|
||||
#endif // INCLUDED_HEADER6
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
// main.c - Cleanup-DuplicateIncludeGuard test
|
||||
|
||||
#include "header1.h"
|
||||
#include "header2.h"
|
||||
#include "header3.h"
|
||||
#include "header3.h"
|
||||
|
||||
#include "header4.h"
|
||||
#include "subfolder/header4.h"
|
||||
#include "subfolder/header5.h"
|
||||
|
||||
#include "header6.h"
|
||||
#include "header7.h"
|
||||
// main.c - Cleanup-DuplicateIncludeGuard test
|
||||
|
||||
#include "header1.h"
|
||||
#include "header2.h"
|
||||
#include "header3.h"
|
||||
#include "header3.h"
|
||||
|
||||
#include "header4.h"
|
||||
#include "subfolder/header4.h"
|
||||
#include "subfolder/header5.h"
|
||||
|
||||
#include "header6.h"
|
||||
#include "header7.h"
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
// header4.h
|
||||
|
||||
#ifndef INCLUDED_HEADER4 // duplicate
|
||||
#define INCLUDED_HEADER4
|
||||
|
||||
// ...
|
||||
|
||||
#endif // INCLUDED_HEADER4
|
||||
// header4.h
|
||||
|
||||
#ifndef INCLUDED_HEADER4 // duplicate
|
||||
#define INCLUDED_HEADER4
|
||||
|
||||
// ...
|
||||
|
||||
#endif // INCLUDED_HEADER4
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
// header5.h
|
||||
|
||||
#ifndef INCLUDED_HEADER4 // duplicate
|
||||
#define INCLUDED_HEADER4
|
||||
|
||||
// ...
|
||||
|
||||
#endif // INCLUDED_HEADER4
|
||||
// header5.h
|
||||
|
||||
#ifndef INCLUDED_HEADER4 // duplicate
|
||||
#define INCLUDED_HEADER4
|
||||
|
||||
// ...
|
||||
|
||||
#endif // INCLUDED_HEADER4
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
|
||||
struct _IO_FILE
|
||||
{
|
||||
// ...
|
||||
};
|
||||
typedef struct _IO_FILE FILE;
|
||||
|
||||
#define va_list void *
|
||||
#define va_start(x, y)
|
||||
#define va_end(x)
|
||||
|
||||
extern int printf(const char *fmt, ...);
|
||||
extern int vprintf(const char *fmt, va_list ap);
|
||||
extern int vfprintf(FILE *stream, const char *format, va_list ap);
|
||||
|
||||
#include "printf1.h"
|
||||
#include "real_world.h"
|
||||
#include "wide_string.h"
|
||||
#include "format.h"
|
||||
#include "pri_macros.h"
|
||||
|
||||
struct _IO_FILE
|
||||
{
|
||||
// ...
|
||||
};
|
||||
typedef struct _IO_FILE FILE;
|
||||
|
||||
#define va_list void *
|
||||
#define va_start(x, y)
|
||||
#define va_end(x)
|
||||
|
||||
extern int printf(const char *fmt, ...);
|
||||
extern int vprintf(const char *fmt, va_list ap);
|
||||
extern int vfprintf(FILE *stream, const char *format, va_list ap);
|
||||
|
||||
#include "printf1.h"
|
||||
#include "real_world.h"
|
||||
#include "wide_string.h"
|
||||
#include "format.h"
|
||||
#include "pri_macros.h"
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
|
||||
struct _IO_FILE
|
||||
{
|
||||
// ...
|
||||
};
|
||||
typedef struct _IO_FILE FILE;
|
||||
|
||||
#define va_list void *
|
||||
#define va_start(x, y)
|
||||
#define va_end(x)
|
||||
|
||||
extern int printf(const char *fmt, ...);
|
||||
extern int vprintf(const char *fmt, va_list ap);
|
||||
extern int vfprintf(FILE *stream, const char *format, va_list ap);
|
||||
|
||||
#include "printf1.h"
|
||||
#include "real_world.h"
|
||||
#include "wide_string.h"
|
||||
#include "format.h"
|
||||
#include "pri_macros.h"
|
||||
|
||||
struct _IO_FILE
|
||||
{
|
||||
// ...
|
||||
};
|
||||
typedef struct _IO_FILE FILE;
|
||||
|
||||
#define va_list void *
|
||||
#define va_start(x, y)
|
||||
#define va_end(x)
|
||||
|
||||
extern int printf(const char *fmt, ...);
|
||||
extern int vprintf(const char *fmt, va_list ap);
|
||||
extern int vfprintf(FILE *stream, const char *format, va_list ap);
|
||||
|
||||
#include "printf1.h"
|
||||
#include "real_world.h"
|
||||
#include "wide_string.h"
|
||||
#include "format.h"
|
||||
#include "pri_macros.h"
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
|
||||
struct _IO_FILE
|
||||
{
|
||||
// ...
|
||||
};
|
||||
typedef struct _IO_FILE FILE;
|
||||
|
||||
#define va_list void *
|
||||
#define va_start(x, y)
|
||||
#define va_end(x)
|
||||
|
||||
extern int printf(const char *fmt, ...);
|
||||
extern int vprintf(const char *fmt, va_list ap);
|
||||
extern int vfprintf(FILE *stream, const char *format, va_list ap);
|
||||
|
||||
#include "printf1.h"
|
||||
#include "real_world.h"
|
||||
#include "wide_string.h"
|
||||
#include "format.h"
|
||||
#include "pri_macros.h"
|
||||
|
||||
struct _IO_FILE
|
||||
{
|
||||
// ...
|
||||
};
|
||||
typedef struct _IO_FILE FILE;
|
||||
|
||||
#define va_list void *
|
||||
#define va_start(x, y)
|
||||
#define va_end(x)
|
||||
|
||||
extern int printf(const char *fmt, ...);
|
||||
extern int vprintf(const char *fmt, va_list ap);
|
||||
extern int vfprintf(FILE *stream, const char *format, va_list ap);
|
||||
|
||||
#include "printf1.h"
|
||||
#include "real_world.h"
|
||||
#include "wide_string.h"
|
||||
#include "format.h"
|
||||
#include "pri_macros.h"
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
|
||||
struct _IO_FILE
|
||||
{
|
||||
// ...
|
||||
};
|
||||
typedef struct _IO_FILE FILE;
|
||||
|
||||
#define va_list void *
|
||||
#define va_start(x, y)
|
||||
#define va_end(x)
|
||||
|
||||
extern int printf(const char *fmt, ...);
|
||||
extern int vprintf(const char *fmt, va_list ap);
|
||||
extern int vfprintf(FILE *stream, const char *format, va_list ap);
|
||||
|
||||
#include "printf1.h"
|
||||
#include "real_world.h"
|
||||
#include "wide_string.h"
|
||||
#include "format.h"
|
||||
#include "pri_macros.h"
|
||||
|
||||
struct _IO_FILE
|
||||
{
|
||||
// ...
|
||||
};
|
||||
typedef struct _IO_FILE FILE;
|
||||
|
||||
#define va_list void *
|
||||
#define va_start(x, y)
|
||||
#define va_end(x)
|
||||
|
||||
extern int printf(const char *fmt, ...);
|
||||
extern int vprintf(const char *fmt, va_list ap);
|
||||
extern int vfprintf(FILE *stream, const char *format, va_list ap);
|
||||
|
||||
#include "printf1.h"
|
||||
#include "real_world.h"
|
||||
#include "wide_string.h"
|
||||
#include "format.h"
|
||||
#include "pri_macros.h"
|
||||
|
||||
@@ -1,54 +1,54 @@
|
||||
// test cases for StackAddressEscapes.ql
|
||||
|
||||
namespace std
|
||||
{
|
||||
class string;
|
||||
|
||||
template<class T> class vector
|
||||
{
|
||||
};
|
||||
};
|
||||
|
||||
class manager
|
||||
{
|
||||
public:
|
||||
manager() {};
|
||||
~manager() {};
|
||||
};
|
||||
|
||||
class resource
|
||||
{
|
||||
public:
|
||||
resource(manager *_m) : m(_m) {};
|
||||
|
||||
void set_strings(std::vector<std::string> const &_strings);
|
||||
|
||||
private:
|
||||
manager *m;
|
||||
std::vector<std::string> const *strings;
|
||||
};
|
||||
|
||||
void resource :: set_strings(std::vector<std::string> const &_strings)
|
||||
{
|
||||
strings = &_strings;
|
||||
}
|
||||
|
||||
manager *glob_man;
|
||||
|
||||
manager *test_managers()
|
||||
{
|
||||
manager man;
|
||||
manager *man_ptr;
|
||||
man_ptr = &man;
|
||||
|
||||
resource a(&man); // BAD: stack address `&man` escapes [NOT DETECTED]
|
||||
resource b(man_ptr); // BAD: stack address `man_ptr` escapes [NOT DETECTED]
|
||||
resource *c = new resource(&man); // BAD: stack address `&man` escapes [NOT DETECTED]
|
||||
|
||||
std::vector<std::string> vs;
|
||||
a.set_strings(vs); // BAD: stack address `&vs` escapes [NOT DETECTED]
|
||||
|
||||
glob_man = &man; // BAD: stack address `&man` escapes
|
||||
|
||||
return &man; // BAD: stack address `&man` escapes [NOT DETECTED]
|
||||
}
|
||||
// test cases for StackAddressEscapes.ql
|
||||
|
||||
namespace std
|
||||
{
|
||||
class string;
|
||||
|
||||
template<class T> class vector
|
||||
{
|
||||
};
|
||||
};
|
||||
|
||||
class manager
|
||||
{
|
||||
public:
|
||||
manager() {};
|
||||
~manager() {};
|
||||
};
|
||||
|
||||
class resource
|
||||
{
|
||||
public:
|
||||
resource(manager *_m) : m(_m) {};
|
||||
|
||||
void set_strings(std::vector<std::string> const &_strings);
|
||||
|
||||
private:
|
||||
manager *m;
|
||||
std::vector<std::string> const *strings;
|
||||
};
|
||||
|
||||
void resource :: set_strings(std::vector<std::string> const &_strings)
|
||||
{
|
||||
strings = &_strings;
|
||||
}
|
||||
|
||||
manager *glob_man;
|
||||
|
||||
manager *test_managers()
|
||||
{
|
||||
manager man;
|
||||
manager *man_ptr;
|
||||
man_ptr = &man;
|
||||
|
||||
resource a(&man); // BAD: stack address `&man` escapes [NOT DETECTED]
|
||||
resource b(man_ptr); // BAD: stack address `man_ptr` escapes [NOT DETECTED]
|
||||
resource *c = new resource(&man); // BAD: stack address `&man` escapes [NOT DETECTED]
|
||||
|
||||
std::vector<std::string> vs;
|
||||
a.set_strings(vs); // BAD: stack address `&vs` escapes [NOT DETECTED]
|
||||
|
||||
glob_man = &man; // BAD: stack address `&man` escapes
|
||||
|
||||
return &man; // BAD: stack address `&man` escapes [NOT DETECTED]
|
||||
}
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
#include "test.c++"
|
||||
#include "test.hpp"
|
||||
#include "test.c++"
|
||||
#include "test.hpp"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "test"
|
||||
#include "test.abc"
|
||||
#include "test.H"
|
||||
#include "test'.h"
|
||||
#include "test"
|
||||
#include "test.abc"
|
||||
#include "test.H"
|
||||
#include "test'.h"
|
||||
|
||||
@@ -1,160 +1,160 @@
|
||||
// bad: gratuitous default constructor
|
||||
class Bad
|
||||
{
|
||||
private:
|
||||
int key;
|
||||
int value;
|
||||
public:
|
||||
Bad();
|
||||
Bad(int);
|
||||
Bad(int, int);
|
||||
int cmp(const Bad& that);
|
||||
};
|
||||
|
||||
Bad::Bad() : key(-1) // non-compliant
|
||||
{
|
||||
}
|
||||
|
||||
Bad::Bad(int k) : key(k) // compliant
|
||||
{
|
||||
}
|
||||
|
||||
Bad::Bad(int k, int v) // compliant
|
||||
{
|
||||
key = k;
|
||||
value = v;
|
||||
}
|
||||
|
||||
int Bad::cmp(const Bad& that)
|
||||
{
|
||||
if(this->key == -1)
|
||||
return 1;
|
||||
if(that.key == -1)
|
||||
return -1;
|
||||
return this->key - that.key;
|
||||
}
|
||||
|
||||
// good: default constructor is necessary because we allocate an array of Good
|
||||
class Good
|
||||
{
|
||||
private:
|
||||
char *cp;
|
||||
public:
|
||||
Good();
|
||||
Good(char *const cpp);
|
||||
char getChar();
|
||||
};
|
||||
|
||||
Good::Good() : cp(0) // compliant
|
||||
{
|
||||
}
|
||||
|
||||
Good::Good(char *const cpp) : cp(cpp)
|
||||
{
|
||||
}
|
||||
|
||||
char Good::getChar()
|
||||
{
|
||||
if(cp == 0)
|
||||
return '\0';
|
||||
return *cp;
|
||||
}
|
||||
|
||||
Good *gd = new Good[16];
|
||||
|
||||
// good: default constructor is necessary because we instantiate a template with AlsoGood
|
||||
class AlsoGood
|
||||
{
|
||||
private:
|
||||
char *cp;
|
||||
public:
|
||||
AlsoGood();
|
||||
AlsoGood(char *const cpp);
|
||||
char getChar();
|
||||
};
|
||||
|
||||
AlsoGood::AlsoGood() // compliant [FALSE POSITIVE]
|
||||
{
|
||||
cp = 0;
|
||||
}
|
||||
|
||||
AlsoGood::AlsoGood(char *const cpp) : cp(cpp)
|
||||
{
|
||||
}
|
||||
|
||||
char AlsoGood::getChar()
|
||||
{
|
||||
if(cp == 0)
|
||||
return '\0';
|
||||
return *cp;
|
||||
}
|
||||
|
||||
template<class T> class Container {
|
||||
private:
|
||||
T *data;
|
||||
public:
|
||||
Container();
|
||||
};
|
||||
|
||||
template<class T> Container<T>::Container()
|
||||
{
|
||||
data = new T();
|
||||
}
|
||||
|
||||
Container<AlsoGood> *foo;
|
||||
|
||||
// good: default constructor is convenient since StillGood is a virtual base class
|
||||
class StillGood
|
||||
{
|
||||
private:
|
||||
char *cp;
|
||||
public:
|
||||
StillGood();
|
||||
StillGood(char *const cpp);
|
||||
char getChar();
|
||||
};
|
||||
|
||||
StillGood::StillGood() : cp(0) // compliant
|
||||
{
|
||||
}
|
||||
|
||||
StillGood::StillGood(char *const cpp) : cp(cpp)
|
||||
{
|
||||
}
|
||||
|
||||
char StillGood::getChar()
|
||||
{
|
||||
if(cp == 0)
|
||||
return '\0';
|
||||
return *cp;
|
||||
}
|
||||
|
||||
class Child : public virtual StillGood
|
||||
{
|
||||
};
|
||||
|
||||
double sqrt(double d);
|
||||
|
||||
// good: members have sensible default values
|
||||
class Coord
|
||||
{
|
||||
private:
|
||||
double x, y;
|
||||
public:
|
||||
Coord();
|
||||
Coord(double, double);
|
||||
double dist();
|
||||
};
|
||||
|
||||
Coord::Coord() : x(0), y(0) // compliant
|
||||
{
|
||||
}
|
||||
|
||||
Coord::Coord(double x, double y) : x(x), y(y)
|
||||
{
|
||||
}
|
||||
|
||||
double Coord::dist()
|
||||
{
|
||||
return sqrt(x*x+y*y);
|
||||
}
|
||||
// bad: gratuitous default constructor
|
||||
class Bad
|
||||
{
|
||||
private:
|
||||
int key;
|
||||
int value;
|
||||
public:
|
||||
Bad();
|
||||
Bad(int);
|
||||
Bad(int, int);
|
||||
int cmp(const Bad& that);
|
||||
};
|
||||
|
||||
Bad::Bad() : key(-1) // non-compliant
|
||||
{
|
||||
}
|
||||
|
||||
Bad::Bad(int k) : key(k) // compliant
|
||||
{
|
||||
}
|
||||
|
||||
Bad::Bad(int k, int v) // compliant
|
||||
{
|
||||
key = k;
|
||||
value = v;
|
||||
}
|
||||
|
||||
int Bad::cmp(const Bad& that)
|
||||
{
|
||||
if(this->key == -1)
|
||||
return 1;
|
||||
if(that.key == -1)
|
||||
return -1;
|
||||
return this->key - that.key;
|
||||
}
|
||||
|
||||
// good: default constructor is necessary because we allocate an array of Good
|
||||
class Good
|
||||
{
|
||||
private:
|
||||
char *cp;
|
||||
public:
|
||||
Good();
|
||||
Good(char *const cpp);
|
||||
char getChar();
|
||||
};
|
||||
|
||||
Good::Good() : cp(0) // compliant
|
||||
{
|
||||
}
|
||||
|
||||
Good::Good(char *const cpp) : cp(cpp)
|
||||
{
|
||||
}
|
||||
|
||||
char Good::getChar()
|
||||
{
|
||||
if(cp == 0)
|
||||
return '\0';
|
||||
return *cp;
|
||||
}
|
||||
|
||||
Good *gd = new Good[16];
|
||||
|
||||
// good: default constructor is necessary because we instantiate a template with AlsoGood
|
||||
class AlsoGood
|
||||
{
|
||||
private:
|
||||
char *cp;
|
||||
public:
|
||||
AlsoGood();
|
||||
AlsoGood(char *const cpp);
|
||||
char getChar();
|
||||
};
|
||||
|
||||
AlsoGood::AlsoGood() // compliant [FALSE POSITIVE]
|
||||
{
|
||||
cp = 0;
|
||||
}
|
||||
|
||||
AlsoGood::AlsoGood(char *const cpp) : cp(cpp)
|
||||
{
|
||||
}
|
||||
|
||||
char AlsoGood::getChar()
|
||||
{
|
||||
if(cp == 0)
|
||||
return '\0';
|
||||
return *cp;
|
||||
}
|
||||
|
||||
template<class T> class Container {
|
||||
private:
|
||||
T *data;
|
||||
public:
|
||||
Container();
|
||||
};
|
||||
|
||||
template<class T> Container<T>::Container()
|
||||
{
|
||||
data = new T();
|
||||
}
|
||||
|
||||
Container<AlsoGood> *foo;
|
||||
|
||||
// good: default constructor is convenient since StillGood is a virtual base class
|
||||
class StillGood
|
||||
{
|
||||
private:
|
||||
char *cp;
|
||||
public:
|
||||
StillGood();
|
||||
StillGood(char *const cpp);
|
||||
char getChar();
|
||||
};
|
||||
|
||||
StillGood::StillGood() : cp(0) // compliant
|
||||
{
|
||||
}
|
||||
|
||||
StillGood::StillGood(char *const cpp) : cp(cpp)
|
||||
{
|
||||
}
|
||||
|
||||
char StillGood::getChar()
|
||||
{
|
||||
if(cp == 0)
|
||||
return '\0';
|
||||
return *cp;
|
||||
}
|
||||
|
||||
class Child : public virtual StillGood
|
||||
{
|
||||
};
|
||||
|
||||
double sqrt(double d);
|
||||
|
||||
// good: members have sensible default values
|
||||
class Coord
|
||||
{
|
||||
private:
|
||||
double x, y;
|
||||
public:
|
||||
Coord();
|
||||
Coord(double, double);
|
||||
double dist();
|
||||
};
|
||||
|
||||
Coord::Coord() : x(0), y(0) // compliant
|
||||
{
|
||||
}
|
||||
|
||||
Coord::Coord(double x, double y) : x(x), y(y)
|
||||
{
|
||||
}
|
||||
|
||||
double Coord::dist()
|
||||
{
|
||||
return sqrt(x*x+y*y);
|
||||
}
|
||||
|
||||
@@ -1,108 +1,108 @@
|
||||
struct HasDtor
|
||||
{
|
||||
~HasDtor();
|
||||
};
|
||||
|
||||
struct Base_NonVirtual_NoDtor
|
||||
{
|
||||
void NonVirtualFunction();
|
||||
};
|
||||
|
||||
struct Base_NonVirtual_VirtualDtor
|
||||
{
|
||||
virtual ~Base_NonVirtual_VirtualDtor();
|
||||
void NonVirtualFunction();
|
||||
};
|
||||
|
||||
struct Base_NonVirtual_NonVirtualDtor
|
||||
{
|
||||
~Base_NonVirtual_NonVirtualDtor();
|
||||
void NonVirtualFunction();
|
||||
};
|
||||
|
||||
struct Base_NonVirtual_ImplicitDtor
|
||||
{
|
||||
HasDtor m_hasDtor;
|
||||
void NonVirtualFunction();
|
||||
};
|
||||
|
||||
struct Derived_NonVirtual_NoDtor : public Base_NonVirtual_NoDtor
|
||||
{
|
||||
};
|
||||
|
||||
struct Derived_NonVirtual_VirtualDtor : public Base_NonVirtual_VirtualDtor
|
||||
{
|
||||
};
|
||||
|
||||
struct Derived_NonVirtual_NonVirtualDtor : public Base_NonVirtual_NonVirtualDtor
|
||||
{
|
||||
};
|
||||
|
||||
struct Derived_NonVirtual_ImplicitDtor : public Base_NonVirtual_ImplicitDtor
|
||||
{
|
||||
};
|
||||
|
||||
struct Base_Virtual_NoDtor
|
||||
{
|
||||
virtual void VirtualFunction();
|
||||
};
|
||||
|
||||
struct Base_Virtual_VirtualDtor
|
||||
{
|
||||
virtual ~Base_Virtual_VirtualDtor();
|
||||
virtual void VirtualFunction();
|
||||
};
|
||||
|
||||
struct Base_Virtual_NonVirtualDtor
|
||||
{
|
||||
~Base_Virtual_NonVirtualDtor();
|
||||
virtual void VirtualFunction();
|
||||
};
|
||||
|
||||
struct Base_Virtual_ImplicitDtor
|
||||
{
|
||||
HasDtor m_hasDtor;
|
||||
virtual void VirtualFunction();
|
||||
};
|
||||
|
||||
struct Base_Virtual_NonVirtualDtorWithDefinition
|
||||
{
|
||||
~Base_Virtual_NonVirtualDtorWithDefinition();
|
||||
virtual void VirtualFunction();
|
||||
};
|
||||
|
||||
Base_Virtual_NonVirtualDtorWithDefinition::~Base_Virtual_NonVirtualDtorWithDefinition()
|
||||
{
|
||||
}
|
||||
|
||||
struct Base_Virtual_NonVirtualDtorWithInlineDefinition
|
||||
{
|
||||
~Base_Virtual_NonVirtualDtorWithInlineDefinition()
|
||||
{
|
||||
}
|
||||
virtual void VirtualFunction();
|
||||
};
|
||||
|
||||
struct Derived_Virtual_NoDtor : public Base_Virtual_NoDtor
|
||||
{
|
||||
};
|
||||
|
||||
struct Derived_Virtual_VirtualDtor : public Base_Virtual_VirtualDtor
|
||||
{
|
||||
};
|
||||
|
||||
struct Derived_Virtual_NonVirtualDtor : public Base_Virtual_NonVirtualDtor
|
||||
{
|
||||
};
|
||||
|
||||
struct Derived_Virtual_ImplicitDtor : public Base_Virtual_ImplicitDtor
|
||||
{
|
||||
};
|
||||
|
||||
struct Derived_Virtual_NonVirtualDtorWithDefinition: public Base_Virtual_NonVirtualDtorWithDefinition
|
||||
{
|
||||
};
|
||||
|
||||
struct Derived_Virtual_NonVirtualDtorWithInlineDefinition: public Base_Virtual_NonVirtualDtorWithInlineDefinition
|
||||
{
|
||||
};
|
||||
struct HasDtor
|
||||
{
|
||||
~HasDtor();
|
||||
};
|
||||
|
||||
struct Base_NonVirtual_NoDtor
|
||||
{
|
||||
void NonVirtualFunction();
|
||||
};
|
||||
|
||||
struct Base_NonVirtual_VirtualDtor
|
||||
{
|
||||
virtual ~Base_NonVirtual_VirtualDtor();
|
||||
void NonVirtualFunction();
|
||||
};
|
||||
|
||||
struct Base_NonVirtual_NonVirtualDtor
|
||||
{
|
||||
~Base_NonVirtual_NonVirtualDtor();
|
||||
void NonVirtualFunction();
|
||||
};
|
||||
|
||||
struct Base_NonVirtual_ImplicitDtor
|
||||
{
|
||||
HasDtor m_hasDtor;
|
||||
void NonVirtualFunction();
|
||||
};
|
||||
|
||||
struct Derived_NonVirtual_NoDtor : public Base_NonVirtual_NoDtor
|
||||
{
|
||||
};
|
||||
|
||||
struct Derived_NonVirtual_VirtualDtor : public Base_NonVirtual_VirtualDtor
|
||||
{
|
||||
};
|
||||
|
||||
struct Derived_NonVirtual_NonVirtualDtor : public Base_NonVirtual_NonVirtualDtor
|
||||
{
|
||||
};
|
||||
|
||||
struct Derived_NonVirtual_ImplicitDtor : public Base_NonVirtual_ImplicitDtor
|
||||
{
|
||||
};
|
||||
|
||||
struct Base_Virtual_NoDtor
|
||||
{
|
||||
virtual void VirtualFunction();
|
||||
};
|
||||
|
||||
struct Base_Virtual_VirtualDtor
|
||||
{
|
||||
virtual ~Base_Virtual_VirtualDtor();
|
||||
virtual void VirtualFunction();
|
||||
};
|
||||
|
||||
struct Base_Virtual_NonVirtualDtor
|
||||
{
|
||||
~Base_Virtual_NonVirtualDtor();
|
||||
virtual void VirtualFunction();
|
||||
};
|
||||
|
||||
struct Base_Virtual_ImplicitDtor
|
||||
{
|
||||
HasDtor m_hasDtor;
|
||||
virtual void VirtualFunction();
|
||||
};
|
||||
|
||||
struct Base_Virtual_NonVirtualDtorWithDefinition
|
||||
{
|
||||
~Base_Virtual_NonVirtualDtorWithDefinition();
|
||||
virtual void VirtualFunction();
|
||||
};
|
||||
|
||||
Base_Virtual_NonVirtualDtorWithDefinition::~Base_Virtual_NonVirtualDtorWithDefinition()
|
||||
{
|
||||
}
|
||||
|
||||
struct Base_Virtual_NonVirtualDtorWithInlineDefinition
|
||||
{
|
||||
~Base_Virtual_NonVirtualDtorWithInlineDefinition()
|
||||
{
|
||||
}
|
||||
virtual void VirtualFunction();
|
||||
};
|
||||
|
||||
struct Derived_Virtual_NoDtor : public Base_Virtual_NoDtor
|
||||
{
|
||||
};
|
||||
|
||||
struct Derived_Virtual_VirtualDtor : public Base_Virtual_VirtualDtor
|
||||
{
|
||||
};
|
||||
|
||||
struct Derived_Virtual_NonVirtualDtor : public Base_Virtual_NonVirtualDtor
|
||||
{
|
||||
};
|
||||
|
||||
struct Derived_Virtual_ImplicitDtor : public Base_Virtual_ImplicitDtor
|
||||
{
|
||||
};
|
||||
|
||||
struct Derived_Virtual_NonVirtualDtorWithDefinition: public Base_Virtual_NonVirtualDtorWithDefinition
|
||||
{
|
||||
};
|
||||
|
||||
struct Derived_Virtual_NonVirtualDtorWithInlineDefinition: public Base_Virtual_NonVirtualDtorWithInlineDefinition
|
||||
{
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user