Skip to content

Commit 34d307e

Browse files
committed
CPP: Test a common false positive.
1 parent a54ee16 commit 34d307e

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
| test.c:15:20:15:25 | call to malloc | This allocation does not include space to null-terminate the string. |
22
| test.c:29:20:29:25 | call to malloc | This allocation does not include space to null-terminate the string. |
33
| test.c:44:20:44:25 | call to malloc | This allocation does not include space to null-terminate the string. |
4+
| test.c:72:17:72:22 | call to malloc | This allocation does not include space to null-terminate the string. |
45
| test.cpp:18:35:18:40 | call to malloc | This allocation does not include space to null-terminate the string. |

cpp/ql/test/query-tests/Security/CWE/CWE-131/semmle/NoSpaceForZeroTerminator/test.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,15 @@ void good3(char *str) {
6363
char *buffer = malloc((strlen(str) + 1) * sizeof(char));
6464
free(buffer);
6565
}
66+
67+
void *memcpy(void *s1, const void *s2, size_t n);
68+
69+
void good4(char *str) {
70+
// GOOD -- allocating a non zero-terminated string [FALSE POSITIVE]
71+
int len = strlen(str);
72+
char *buffer = malloc(len);
73+
74+
memcpy(buffer, str, len);
75+
76+
free(buffer);
77+
}

0 commit comments

Comments
 (0)