diff --git a/sycl/source/detail/device_info.hpp b/sycl/source/detail/device_info.hpp index 959094d018d3e..41c1dd67969a9 100644 --- a/sycl/source/detail/device_info.hpp +++ b/sycl/source/detail/device_info.hpp @@ -208,11 +208,16 @@ device_impl::get_device_info_string(ur_device_info_t InfoCode) const { if (resultSize == 0) { return std::string(); } - std::unique_ptr result(new char[resultSize]); + std::string result; + // C++23's `resize_and_overwrite` would be better... + // + // UR counts null terminator in the size, std::string doesn't. Adjust by "-1" + // for that. + result.resize(resultSize - 1); getAdapter()->call( - getHandleRef(), InfoCode, resultSize, result.get(), nullptr); + getHandleRef(), InfoCode, resultSize, result.data(), nullptr); - return std::string(result.get()); + return result; } // Specialization for string return type, variable return size