-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16939 from geoffw0/docsforautofix
C++: Assorted minor doc improvements
- Loading branch information
Showing
22 changed files
with
330 additions
and
209 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 0 additions & 7 deletions
7
cpp/ql/src/Likely Bugs/Memory Management/ReturnStackAllocatedMemory.cpp
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
cpp/ql/src/Likely Bugs/Memory Management/ReturnStackAllocatedMemoryBad.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Record *mkRecord(int value) { | ||
Record myRecord(value); | ||
|
||
return &myRecord; // BAD: returns a pointer to `myRecord`, which is a stack-allocated object. | ||
} |
5 changes: 5 additions & 0 deletions
5
cpp/ql/src/Likely Bugs/Memory Management/ReturnStackAllocatedMemoryGood.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Record *mkRecord(int value) { | ||
Record *myRecord = new Record(value); | ||
|
||
return myRecord; // GOOD: returns a pointer to a `myRecord`, which is a heap-allocated object. | ||
} |
17 changes: 13 additions & 4 deletions
17
cpp/ql/src/Security/CWE/CWE-191/UnsignedDifferenceExpressionComparedZero.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,14 @@ | ||
unsigned limit = get_limit(); | ||
unsigned total = 0; | ||
while (limit - total > 0) { // wrong: if `total` is greater than `limit` this will underflow and continue executing the loop. | ||
uint32_t limit = get_limit(); | ||
uint32_t total = 0; | ||
|
||
while (limit - total > 0) { // BAD: if `total` is greater than `limit` this will underflow and continue executing the loop. | ||
total += get_data(); | ||
} | ||
} | ||
|
||
while (total < limit) { // GOOD: never underflows here because there is no arithmetic. | ||
total += get_data(); | ||
} | ||
|
||
while ((int64_t)limit - total > 0) { // GOOD: never underflows here because the result always fits in an `int64_t`. | ||
total += get_data(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,17 @@ | ||
char *file_name; | ||
FILE *f_ptr; | ||
|
||
/* Initialize file_name */ | ||
|
||
f_ptr = fopen(file_name, "w"); | ||
if (f_ptr == NULL) { | ||
/* Handle error */ | ||
} | ||
|
||
/* ... */ | ||
|
||
if (chmod(file_name, S_IRUSR) == -1) { | ||
/* Handle error */ | ||
} | ||
} | ||
|
||
fclose(f_ptr); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 29 additions & 2 deletions
31
cpp/ql/src/Security/CWE/CWE-732/DoNotCreateWorldWritable.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,38 @@ | ||
void write_default_config_bad() { | ||
// BAD - this is world-writable so any user can overwrite the config | ||
int out = creat(OUTFILE, 0666); | ||
dprintf(out, DEFAULT_CONFIG); | ||
if (out < 0) { | ||
// handle error | ||
} | ||
|
||
dprintf(out, "%s", DEFAULT_CONFIG); | ||
close(out); | ||
} | ||
|
||
void write_default_config_good() { | ||
// GOOD - this allows only the current user to modify the file | ||
int out = creat(OUTFILE, S_IWUSR | S_IRUSR); | ||
dprintf(out, DEFAULT_CONFIG); | ||
if (out < 0) { | ||
// handle error | ||
} | ||
|
||
dprintf(out, "%s", DEFAULT_CONFIG); | ||
close(out); | ||
} | ||
|
||
void write_default_config_good_2() { | ||
// GOOD - this allows only the current user to modify the file | ||
int out = open(OUTFILE, O_WRONLY | O_CREAT, S_IWUSR | S_IRUSR); | ||
if (out < 0) { | ||
// handle error | ||
} | ||
|
||
FILE *fd = fdopen(out, "w"); | ||
if (fd == NULL) { | ||
close(out); | ||
// handle error | ||
} | ||
|
||
fprintf(fd, "%s", DEFAULT_CONFIG); | ||
fclose(fd); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 12 additions & 12 deletions
24
...ormat/WrongTypeFormatArguments/Linux_mixed_byte_wprintf/WrongTypeFormatArguments.expected
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
| tests.cpp:18:15:18:22 | Hello | This argument should be of type 'char *' but is of type 'char16_t *'. | | ||
| tests.cpp:19:15:19:22 | Hello | This argument should be of type 'char *' but is of type 'wchar_t *'. | | ||
| tests.cpp:21:15:21:21 | Hello | This argument should be of type 'char16_t *' but is of type 'char *'. | | ||
| tests.cpp:21:15:21:21 | Hello | This argument should be of type 'wchar_t *' but is of type 'char *'. | | ||
| tests.cpp:26:17:26:24 | Hello | This argument should be of type 'char *' but is of type 'char16_t *'. | | ||
| tests.cpp:30:17:30:24 | Hello | This argument should be of type 'wchar_t *' but is of type 'char16_t *'. | | ||
| tests.cpp:35:36:35:43 | Hello | This argument should be of type 'char *' but is of type 'wchar_t *'. | | ||
| tests.cpp:39:36:39:43 | Hello | This argument should be of type 'char16_t *' but is of type 'wchar_t *'. | | ||
| tests.cpp:42:37:42:44 | Hello | This argument should be of type 'char *' but is of type 'char16_t *'. | | ||
| tests.cpp:43:37:43:44 | Hello | This argument should be of type 'char *' but is of type 'wchar_t *'. | | ||
| tests.cpp:45:37:45:43 | Hello | This argument should be of type 'char16_t *' but is of type 'char *'. | | ||
| tests.cpp:47:37:47:44 | Hello | This argument should be of type 'char16_t *' but is of type 'wchar_t *'. | | ||
| tests.cpp:18:15:18:22 | Hello | This format specifier for type 'char *' does not match the argument type 'char16_t *'. | | ||
| tests.cpp:19:15:19:22 | Hello | This format specifier for type 'char *' does not match the argument type 'wchar_t *'. | | ||
| tests.cpp:21:15:21:21 | Hello | This format specifier for type 'char16_t *' does not match the argument type 'char *'. | | ||
| tests.cpp:21:15:21:21 | Hello | This format specifier for type 'wchar_t *' does not match the argument type 'char *'. | | ||
| tests.cpp:26:17:26:24 | Hello | This format specifier for type 'char *' does not match the argument type 'char16_t *'. | | ||
| tests.cpp:30:17:30:24 | Hello | This format specifier for type 'wchar_t *' does not match the argument type 'char16_t *'. | | ||
| tests.cpp:35:36:35:43 | Hello | This format specifier for type 'char *' does not match the argument type 'wchar_t *'. | | ||
| tests.cpp:39:36:39:43 | Hello | This format specifier for type 'char16_t *' does not match the argument type 'wchar_t *'. | | ||
| tests.cpp:42:37:42:44 | Hello | This format specifier for type 'char *' does not match the argument type 'char16_t *'. | | ||
| tests.cpp:43:37:43:44 | Hello | This format specifier for type 'char *' does not match the argument type 'wchar_t *'. | | ||
| tests.cpp:45:37:45:43 | Hello | This format specifier for type 'char16_t *' does not match the argument type 'char *'. | | ||
| tests.cpp:47:37:47:44 | Hello | This format specifier for type 'char16_t *' does not match the argument type 'wchar_t *'. | |
8 changes: 4 additions & 4 deletions
8
...s/Format/WrongTypeFormatArguments/Linux_mixed_word_size/WrongTypeFormatArguments.expected
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
| tests_32.cpp:14:16:14:23 | void_ptr | This argument should be of type 'long' but is of type 'void *'. | | ||
| tests_32.cpp:15:15:15:15 | l | This argument should be of type 'void *' but is of type 'long'. | | ||
| tests_64.cpp:14:16:14:23 | void_ptr | This argument should be of type 'long' but is of type 'void *'. | | ||
| tests_64.cpp:15:15:15:15 | l | This argument should be of type 'void *' but is of type 'long'. | | ||
| tests_32.cpp:14:16:14:23 | void_ptr | This format specifier for type 'long' does not match the argument type 'void *'. | | ||
| tests_32.cpp:15:15:15:15 | l | This format specifier for type 'void *' does not match the argument type 'long'. | | ||
| tests_64.cpp:14:16:14:23 | void_ptr | This format specifier for type 'long' does not match the argument type 'void *'. | | ||
| tests_64.cpp:15:15:15:15 | l | This format specifier for type 'void *' does not match the argument type 'long'. | |
Oops, something went wrong.