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

Skip to content

Commit 2f290bd

Browse files
committed
C++: Additional test cases.
1 parent b9bc216 commit 2f290bd

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

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

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,3 +107,19 @@ void bad9(wchar_t *wstr) {
107107
wcscpy(wbuffer, wstr);
108108
delete wbuffer;
109109
}
110+
111+
void good3(char *str) {
112+
// GOOD -- zero-termination not required for this printf
113+
char *buffer = (char *)malloc(strlen(str));
114+
decode(buffer, str);
115+
wprintf(L"%p", buffer);
116+
free(buffer);
117+
}
118+
119+
void good4(char *str) {
120+
// GOOD -- zero-termination not required for this printf
121+
char *buffer = (char *)malloc(strlen(str));
122+
decode(buffer, str);
123+
wprintf(L"%.*s", strlen(str), buffer);
124+
free(buffer);
125+
}

0 commit comments

Comments
 (0)