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

Commit a01364e

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 b9e2fdb commit a01364e

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

test/test-subsystem/TESTSubsystemString.cpp

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

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

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

0 commit comments

Comments
 (0)