Skip to content

Commit 7427d25

Browse files
KFilipekCopilot
andauthored
Update test/ctl/ctl_api.cpp
AI suggested Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 63c8f9e commit 7427d25

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

test/ctl/ctl_api.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,17 @@ class Pool {
101101
umf_result_t ret;
102102
char ret_buf[256] = {0};
103103
if constexpr (std::is_same_v<T, std::string>) {
104-
strncpy(ret_buf, value.c_str(), sizeof(ret_buf));
104+
strncpy(ret_buf, value.c_str(), sizeof(ret_buf) - 1);
105+
ret_buf[sizeof(ret_buf) - 1] = '\0'; // Ensure null-termination
106+
ret = ctlApiFunction(name, disableContext ? nullptr : pool,
107+
(void *)ret_buf, sizeof(ret_buf));
108+
} else if constexpr (std::is_arithmetic_v<T>) {
109+
std::string value_str = std::to_string(value);
110+
strncpy(ret_buf, value_str.c_str(), sizeof(ret_buf) - 1);
111+
ret_buf[sizeof(ret_buf) - 1] = '\0'; // Ensure null-termination
105112
ret = ctlApiFunction(name, disableContext ? nullptr : pool,
106113
(void *)ret_buf, sizeof(ret_buf));
107114
} else {
108-
strncpy(ret_buf, value, sizeof(value));
109115
ret = ctlApiFunction(name, disableContext ? nullptr : pool, &value,
110116
sizeof(value));
111117
}

0 commit comments

Comments
 (0)