diff --git a/level_zero/sysman/test/unit_tests/sources/linux/mock_sysman_fixture.h b/level_zero/sysman/test/unit_tests/sources/linux/mock_sysman_fixture.h index 4bea71a1f7..912ce32b23 100644 --- a/level_zero/sysman/test/unit_tests/sources/linux/mock_sysman_fixture.h +++ b/level_zero/sysman/test/unit_tests/sources/linux/mock_sysman_fixture.h @@ -45,8 +45,8 @@ class SysmanDeviceFixture : public ::testing::Test { public: void SetUp() override { VariableBackup mockRealPath(&NEO::SysCalls::sysCallsRealpath, [](const char *path, char *buf) -> char * { - std::string str = "/sys/devices/pci0000:00/0000:00:02.0"; - buf = const_cast(str.c_str()); + constexpr size_t sizeofPath = sizeof("/sys/devices/pci0000:00/0000:00:02.0"); + strcpy_s(buf, sizeofPath, "/sys/devices/pci0000:00/0000:00:02.0"); return buf; }); @@ -90,8 +90,8 @@ class SysmanMultiDeviceFixture : public ::testing::Test { public: void SetUp() override { VariableBackup mockRealPath(&NEO::SysCalls::sysCallsRealpath, [](const char *path, char *buf) -> char * { - std::string str = "/sys/devices/pci0000:00/0000:00:02.0"; - buf = const_cast(str.c_str()); + constexpr size_t sizeofPath = sizeof("/sys/devices/pci0000:00/0000:00:02.0"); + strcpy_s(buf, sizeofPath, "/sys/devices/pci0000:00/0000:00:02.0"); return buf; }); diff --git a/level_zero/sysman/test/unit_tests/sources/linux/test_sysman_driver.cpp b/level_zero/sysman/test/unit_tests/sources/linux/test_sysman_driver.cpp index cdadedb30c..f29280a41b 100644 --- a/level_zero/sysman/test/unit_tests/sources/linux/test_sysman_driver.cpp +++ b/level_zero/sysman/test/unit_tests/sources/linux/test_sysman_driver.cpp @@ -6,6 +6,7 @@ */ #include "shared/source/helpers/hw_info.h" +#include "shared/source/helpers/string.h" #include "shared/test/common/helpers/default_hw_info.h" #include "shared/test/common/helpers/variable_backup.h" #include "shared/test/common/mocks/mock_execution_environment.h" @@ -74,8 +75,8 @@ struct SysmanDriverTestMultipleFamilySupport : public ::testing::Test { TEST_F(SysmanDriverTestMultipleFamilySupport, whenInitializingSysmanDriverWithArrayOfDevicesThenDriverIsInitializedOnlyWithThoseSupported) { VariableBackup mockRealPath(&NEO::SysCalls::sysCallsRealpath, [](const char *path, char *buf) -> char * { - std::string str = "/sys/devices/pci0000:00/0000:00:02.0"; - buf = const_cast(str.c_str()); + constexpr size_t sizeofPath = sizeof("/sys/devices/pci0000:00/0000:00:02.0"); + strcpy_s(buf, sizeofPath, "/sys/devices/pci0000:00/0000:00:02.0"); return buf; }); @@ -142,8 +143,8 @@ struct SysmanDriverTestNoDeviceCreate : public ::testing::Test { TEST_F(SysmanDriverTestNoDeviceCreate, GivenReadLinkSysCallFailWhenInitializingSysmanDriverWithArrayOfDevicesThenSysmanDeviceCreateFailAndDriverIsNull) { VariableBackup mockRealPath(&NEO::SysCalls::sysCallsRealpath, [](const char *path, char *buf) -> char * { - std::string str = "/sys/devices/pci0000:00/0000:00:02.0"; - buf = const_cast(str.c_str()); + constexpr size_t sizeofPath = sizeof("/sys/devices/pci0000:00/0000:00:02.0"); + strcpy_s(buf, sizeofPath, "/sys/devices/pci0000:00/0000:00:02.0"); return buf; }); @@ -173,8 +174,8 @@ TEST_F(SysmanDriverTestNoDeviceCreate, GivenRealpathSysCallFailWhenInitializingS struct SysmanDriverHandleTest : public ::testing::Test { void SetUp() override { VariableBackup mockRealPath(&NEO::SysCalls::sysCallsRealpath, [](const char *path, char *buf) -> char * { - std::string str = "/sys/devices/pci0000:00/0000:00:02.0"; - buf = const_cast(str.c_str()); + constexpr size_t sizeofPath = sizeof("/sys/devices/pci0000:00/0000:00:02.0"); + strcpy_s(buf, sizeofPath, "/sys/devices/pci0000:00/0000:00:02.0"); return buf; });