From 7985bfe362e12610506688c62a332c54a5f61002 Mon Sep 17 00:00:00 2001 From: Oleksandr Pavlyk Date: Tue, 2 Nov 2021 15:37:48 -0500 Subject: [PATCH] set the last byte in allocated char array to zero. --- dpctl-capi/helper/include/dpctl_string_utils.hpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/dpctl-capi/helper/include/dpctl_string_utils.hpp b/dpctl-capi/helper/include/dpctl_string_utils.hpp index 3b1d0ae73c..aa1a8a9535 100644 --- a/dpctl-capi/helper/include/dpctl_string_utils.hpp +++ b/dpctl-capi/helper/include/dpctl_string_utils.hpp @@ -50,6 +50,11 @@ cstring_from_string(const std::string &str) #else std::strncpy(cstr, str.c_str(), cstr_len); #endif + // Added to resolve CheckMarx's false positive. + // NB: This is redundant because str.c_str() is guaranteed + // to be null-terminated and the copy function is asked to + // copy enough characters to include that null-character. + cstr[cstr_len - 1] = '\0'; } catch (std::bad_alloc const &ba) { // \todo log error std::cerr << ba.what() << '\n';