Skip to content

Commit 5254c96

Browse files
oleksandr-pavlykPokhodenkoSA
authored andcommitted
set the last byte in allocated char array to zero. (#650)
1 parent 8f21b44 commit 5254c96

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

dpctl-capi/helper/include/dpctl_string_utils.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ cstring_from_string(const std::string &str)
5050
#else
5151
std::strncpy(cstr, str.c_str(), cstr_len);
5252
#endif
53+
// Added to resolve CheckMarx's false positive.
54+
// NB: This is redundant because str.c_str() is guaranteed
55+
// to be null-terminated and the copy function is asked to
56+
// copy enough characters to include that null-character.
57+
cstr[cstr_len - 1] = '\0';
5358
} catch (std::bad_alloc const &ba) {
5459
// \todo log error
5560
std::cerr << ba.what() << '\n';

0 commit comments

Comments
 (0)