mirror of
https://github.com/github/codeql.git
synced 2026-03-27 17:58:17 +01:00
CPP: Fix the example code.
This commit is contained in:
@@ -1,13 +1,13 @@
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
char param[SIZE];
|
||||
char param[20];
|
||||
char *arg1;
|
||||
|
||||
char arg1[10];
|
||||
char arg2[20];
|
||||
arg1 = argv[1];
|
||||
|
||||
//wrong: only uses the size of the source (argv[1]) when using strncpy
|
||||
strncpy(param, argv[1], strlen(arg1));
|
||||
strncpy(param, arg1, strlen(arg1));
|
||||
|
||||
//correct: uses the size of the destination array as well
|
||||
strncpy(param, argv[1], min(strlen(arg1, sizeof(param) -1)));
|
||||
strncpy(param, arg1, min(strlen(arg1), sizeof(param) -1));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user