diff options
author | Sylvain Joubert <joubert.sy@gmail.com> | 2016-08-25 09:54:28 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2016-08-25 14:56:50 (GMT) |
commit | cd344e3a62e3a6728e5b749cb923104c2c09949c (patch) | |
tree | b6463f57d9c0922df833a0e9efc91dedb7cab5ab | |
parent | 98caa14cc84cc659c2c5b51f84c6547b57c89c30 (diff) | |
download | CMake-cd344e3a62e3a6728e5b749cb923104c2c09949c.zip CMake-cd344e3a62e3a6728e5b749cb923104c2c09949c.tar.gz CMake-cd344e3a62e3a6728e5b749cb923104c2c09949c.tar.bz2 |
create_test_sourcelist: Use safer strncpy instead of strcpy
Clang-tidy advises to use a safer function in place of strcpy.
This should avoid such warnings in user build using clang-tidy.
-rw-r--r-- | Templates/TestDriver.cxx.in | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/Templates/TestDriver.cxx.in b/Templates/TestDriver.cxx.in index ffa6999..3e0afa5 100644 --- a/Templates/TestDriver.cxx.in +++ b/Templates/TestDriver.cxx.in @@ -33,19 +33,21 @@ static functionMapEntry cmakeGeneratedFunctionMapEntries[] = { static char* lowercase(const char *string) { char *new_string, *p; + size_t stringSize = 0; #ifdef __cplusplus - new_string = static_cast<char *>(malloc(sizeof(char) * - static_cast<size_t>(strlen(string) + 1))); + stringSize = static_cast<size_t>(strlen(string) + 1); + new_string = static_cast<char *>(malloc(sizeof(char) * stringSize)); #else - new_string = (char *)(malloc(sizeof(char) * (size_t)(strlen(string) + 1))); + stringSize = (size_t)(strlen(string) + 1); + new_string = (char *)(malloc(sizeof(char) * stringSize)); #endif if (!new_string) { return 0; } - strcpy(new_string, string); + strncpy(new_string, string, stringSize); p = new_string; while (*p != 0) { |