From bae72f14883742cf824f89704e8d9754cbce3fdd Mon Sep 17 00:00:00 2001 From: Sven Trittler Date: Fri, 22 Mar 2024 15:20:40 +0100 Subject: [PATCH] serdata_print: fix windows --- .../include/org/eclipse/cyclonedds/topic/datatopic.hpp | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/ddscxx/include/org/eclipse/cyclonedds/topic/datatopic.hpp b/src/ddscxx/include/org/eclipse/cyclonedds/topic/datatopic.hpp index dad87bcc..1038bb9b 100644 --- a/src/ddscxx/include/org/eclipse/cyclonedds/topic/datatopic.hpp +++ b/src/ddscxx/include/org/eclipse/cyclonedds/topic/datatopic.hpp @@ -634,14 +634,10 @@ size_t serdata_print( const std::string data = ss.str(); const size_t len = data.size(); + copy_len = len < bufsize ? len : bufsize; - copy_len = bufsize - 1; - if (len < bufsize) { - copy_len = len; - } - - strncpy(buf, data.c_str(), copy_len); - buf[copy_len] = '\0'; // Null-terminate the string + std::copy_n(data.c_str(), copy_len, buf); + buf[len < bufsize ? copy_len : copy_len - 1] = '\0'; } return copy_len;