From f85889d052b364508317b268ade886ba7c15972a Mon Sep 17 00:00:00 2001 From: Geoffrey White <40627776+geoffw0@users.noreply.github.com> Date: Tue, 16 Oct 2018 16:08:55 +0100 Subject: [PATCH] CPP: Fix the example code. --- cpp/ql/src/Critical/OverflowDestination.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/cpp/ql/src/Critical/OverflowDestination.cpp b/cpp/ql/src/Critical/OverflowDestination.cpp index 1a758430bf4..02c5281d0b6 100644 --- a/cpp/ql/src/Critical/OverflowDestination.cpp +++ b/cpp/ql/src/Critical/OverflowDestination.cpp @@ -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)); }