Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5bf88f0

Browse files
C++: Fix mixed tabs and spaces in non-test code
1 parent 0afbea9 commit 5bf88f0

17 files changed

Lines changed: 127 additions & 127 deletions

File tree

cpp/ql/src/Architecture/Refactoring Opportunities/FunctionsWithManyParameters.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ void fillRect(int x, int y, int w, int h,
44
int r2, int g2, int b2, int a2,
55
gradient_type grad, unsigned int flags, bool border)
66
{
7-
// ...
7+
// ...
88
}

cpp/ql/src/Best Practices/Likely Errors/OffsetUseBeforeRangeCheck.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
int find(int start, char *str, char goal)
22
{
33
int len = strlen(str);
4-
//Potential buffer overflow
4+
//Potential buffer overflow
55
for (int i = start; str[i] != 0 && i < len; i++) {
66
if (str[i] == goal)
77
return i;
@@ -12,7 +12,7 @@ int find(int start, char *str, char goal)
1212
int findRangeCheck(int start, char *str, char goal)
1313
{
1414
int len = strlen(str);
15-
//Range check protects against buffer overflow
15+
//Range check protects against buffer overflow
1616
for (int i = start; i < len && str[i] != 0 ; i++) {
1717
if (str[i] == goal)
1818
return i;
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
void sanitize(Fields[] record) {
22
//The number of fields here can be put in a const
3-
for (fieldCtr = 0; field < 7; field++) {
4-
sanitize(fields[fieldCtr]);
5-
}
3+
for (fieldCtr = 0; field < 7; field++) {
4+
sanitize(fields[fieldCtr]);
5+
}
66
}
77

88
#define NUM_FIELDS 7
99

1010
void process(Fields[] record) {
11-
//This avoids using a magic constant by using the macro instead
12-
for (fieldCtr = 0; field < NUM_FIELDS; field++) {
13-
process(fields[fieldCtr]);
14-
}
11+
//This avoids using a magic constant by using the macro instead
12+
for (fieldCtr = 0; field < NUM_FIELDS; field++) {
13+
process(fields[fieldCtr]);
14+
}
1515
}
1616

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
//start of file
22
static void f() { //static function f() is unused in the file
3-
//...
3+
//...
44
}
55
static void g() {
6-
//...
6+
//...
77
}
88
void public_func() { //non-static function public_func is not called in file,
99
//but could be visible in other files
10-
//...
11-
g(); //call to g()
12-
//...
10+
//...
11+
g(); //call to g()
12+
//...
1313
}
1414
//end of file
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
typedef struct Names {
2-
char first[100];
3-
char last[100];
2+
char first[100];
3+
char last[100];
44
} Names;
55

66
int doFoo(Names n) { //wrong: n is passed by value (meaning the entire structure
77
//is copied onto the stack, instead of just a pointer)
8-
...
8+
...
99
}
1010

1111
int doBar(Names &n) { //better, only a reference is passed
12-
...
12+
...
1313
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
Record records[SIZE] = ...;
22

33
int f() {
4-
int recordIdx = 0;
5-
recordIdx = readUserInput(); //recordIdx is returned from a function
4+
int recordIdx = 0;
5+
recordIdx = readUserInput(); //recordIdx is returned from a function
66
// there is no check so it could be negative
7-
doFoo(&(records[recordIdx])); //but is not checked before use as an array offset
7+
doFoo(&(records[recordIdx])); //but is not checked before use as an array offset
88
}
99

cpp/ql/src/Likely Bugs/Likely Typos/BoolValueInBitOp.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
if (!flags & SOME_BIT) { //wrong: '!' has higher precedence than '&', so this
2-
// is bracketed as '(!flags) & SOME_BIT', and does not
3-
// check whether a particular bit is set.
4-
// ...
2+
// is bracketed as '(!flags) & SOME_BIT', and does not
3+
// check whether a particular bit is set.
4+
// ...
55
}
66

77
if ((p != NULL) & p->f()) { //wrong: The use of '&' rather than '&&' will still
8-
// de-reference the pointer even if it is NULL.
9-
// ...
8+
// de-reference the pointer even if it is NULL.
9+
// ...
1010
}
1111

1212
int bits = (s > 8) & 0xff; //wrong: Invalid attempt to get the 8 most significant
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
int x1 = 0;
22
for (x1 = 0; x1 < 100; x1++) {
3-
int x2 = 0;
4-
for (x1 = 0; x1 < 300; x1++) {
3+
int x2 = 0;
4+
for (x1 = 0; x1 < 300; x1++) {
55
// this is most likely a typo
66
// the outer loop will exit immediately
7-
}
7+
}
88
}
99

1010
for (x1 = 0; x1 < 100; x1++) {
1111
if(x1 == 10 && condition) {
12-
for (; x1 < 75; x1++) {
12+
for (; x1 < 75; x1++) {
1313
// this should be written as a while loop
14-
}
14+
}
1515
}
1616
}
Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
11
class Base {
22
public:
3-
Resource *p;
4-
Base() {
5-
p = createResource();
6-
}
7-
//...
8-
~Base() {
9-
//wrong: this destructor is non-virtual, but Base has a derived class
10-
// with a non-virtual destructor
11-
freeResource(p);
12-
}
3+
Resource *p;
4+
Base() {
5+
p = createResource();
6+
}
7+
//...
8+
~Base() {
9+
//wrong: this destructor is non-virtual, but Base has a derived class
10+
//with a non-virtual destructor
11+
freeResource(p);
12+
}
1313
};
1414

1515
class Derived: public Base {
1616
public:
17-
Resource *dp;
18-
Derived() {
19-
dp = createResource2();
20-
}
21-
~Derived() {
22-
freeResource2(dp);
23-
}
17+
Resource *dp;
18+
Derived() {
19+
dp = createResource2();
20+
}
21+
~Derived() {
22+
freeResource2(dp);
23+
}
2424
};
2525

2626
int f() {
27-
Base *b = new Derived(); //creates resources for both Base::p and Derived::dp
28-
//...
29-
delete b; //will only call Base::~Base(), leaking the resource dp.
27+
Base *b = new Derived(); //creates resources for both Base::p and Derived::dp
28+
//...
29+
delete b; //will only call Base::~Base(), leaking the resource dp.
3030
// Change both destructors to virtual to ensure they are both called.
3131
}
Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,35 @@
11
class Base {
22
protected:
3-
Resource* resource;
3+
Resource* resource;
44
public:
5-
virtual void init() {
6-
resource = createResource();
7-
}
8-
virtual void release() {
9-
freeResource(resource);
10-
}
5+
virtual void init() {
6+
resource = createResource();
7+
}
8+
virtual void release() {
9+
freeResource(resource);
10+
}
1111
};
1212

1313
class Derived: public Base {
14-
virtual void init() {
15-
resource = createResourceV2();
16-
}
17-
virtual void release() {
18-
freeResourceV2(resource);
19-
}
14+
virtual void init() {
15+
resource = createResourceV2();
16+
}
17+
virtual void release() {
18+
freeResourceV2(resource);
19+
}
2020
};
2121

2222
Base::Base() {
23-
this->init();
23+
this->init();
2424
}
2525
Base::~Base() {
26-
this->release();
26+
this->release();
2727
}
2828

2929
int f() {
30-
// this will call Base::Base() and then Derived::Derived(), but this->init()
31-
// inBase::Base() will resolve to Base::init(), not Derived::init()
32-
// The reason for this is that when Base::Base is called, the object being
33-
// created is still of type Base (including the vtable)
34-
Derived* d = new Derived();
30+
// this will call Base::Base() and then Derived::Derived(), but this->init()
31+
// inBase::Base() will resolve to Base::init(), not Derived::init()
32+
// The reason for this is that when Base::Base is called, the object being
33+
// created is still of type Base (including the vtable)
34+
Derived* d = new Derived();
3535
}

0 commit comments

Comments
 (0)