Hi,

Please find attach a patch that clean the test driver source regarding
clang-tidy checks.

Especially, I've replaced the use of strcpy by strncpy.
This should avoid users to get clang-tidy warnings in their build from
CMake generated code.

Regards,
Sylvain
From 5911196a9b05234220fa7916cd58a4bc6ba35556 Mon Sep 17 00:00:00 2001
From: Sylvain Joubert <joubert...@gmail.com>
Date: Thu, 25 Aug 2016 11:54:28 +0200
Subject: [PATCH] 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.
---
 Templates/TestDriver.cxx.in | 10 ++++++----
 1 file 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)
     {
-- 
2.9.3

-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake-developers

Reply via email to