Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions src/runtime_src/core/common/api/xrt_error.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,6 @@
#include <map>
#include <cstring>

#ifdef _WIN32
# pragma warning( disable : 4996)
#endif

namespace {

static auto code_to_string = [] (auto& map, auto code, const std::string& msg)
Expand Down Expand Up @@ -350,11 +346,11 @@ xrtErrorGetString(xrtDeviceHandle, xrtErrorCode error, char* out, size_t len, si
if (out_len)
*out_len = str.size() + 1;

if (!out)
if (!out || len == 0)
return 0;

auto cp_len = std::min(len-1, str.size());
std::strncpy(out, str.c_str(), cp_len);
std::memcpy(out, str.c_str(), cp_len);
out[cp_len] = 0;

return 0;
Expand Down
11 changes: 8 additions & 3 deletions src/runtime_src/core/common/api/xrt_xclbin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1748,10 +1748,15 @@ xrtXclbinGetXSAName(xrtXclbinHandle handle, char* name, int size, int* ret_size)
const std::string& xsaname = xclbin->get_xsa_name();
// populate ret_size if memory is allocated
if (ret_size)
*ret_size = xsaname.size();
*ret_size = xsaname.size() + 1;
Comment thread
hyunjiki-amd marked this conversation as resolved.
// populate name if memory is allocated
if (name)
std::strncpy(name, xsaname.c_str(), size);
if (!name || size == 0)
return 0;

auto cp_len = std::min(size - 1, static_cast<int>(xsaname.size()));
std::memcpy(name, xsaname.c_str(), cp_len);
name[cp_len] = 0;

return 0;
});
}
Expand Down
Loading