Skip to content
This repository was archived by the owner on Aug 5, 2022. It is now read-only.

Commit 8af936e

Browse files
committed
Klocwork fix: removing strncpy call
This patch reworks the code to avoid calling the strncpy method, which is considered as unsafe on windows. Signed-off-by: Thomas Cahuzac <[email protected]>
1 parent c64315c commit 8af936e

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

test/test-subsystem/TESTSubsystemString.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2929
*/
3030
#include <string.h>
31+
#include <iterator>
32+
#include <Iterator.hpp>
3133
#include "TESTSubsystemString.h"
3234

3335
#define base CTESTSubsystemObject
@@ -46,5 +48,6 @@ std::string CTESTSubsystemString::toString(const void *pvValue, size_t /*size*/)
4648

4749
void CTESTSubsystemString::fromString(const std::string &strValue, void *pvValue, size_t size)
4850
{
49-
strncpy((char *)pvValue, strValue.c_str(), size);
51+
auto destination = MAKE_ARRAY_ITERATOR(static_cast<char *>(pvValue), size);
52+
std::copy_n(std::begin(strValue), size, destination);
5053
}

0 commit comments

Comments
 (0)