diff --git a/source/adapters/cuda/common.cpp b/source/adapters/cuda/common.cpp index f2b6dae841..bb7584d39d 100644 --- a/source/adapters/cuda/common.cpp +++ b/source/adapters/cuda/common.cpp @@ -110,7 +110,11 @@ thread_local char ErrorMessage[MaxMessageSize]; [[maybe_unused]] void setErrorMessage(const char *pMessage, ur_result_t ErrorCode) { assert(strlen(pMessage) <= MaxMessageSize); - strcpy(ErrorMessage, pMessage); +#if defined(_WIN32) + strncpy_s(ErrorMessage, MaxMessageSize, pMessage, strlen(pMessage)); +#else + strncpy(ErrorMessage, pMessage, MaxMessageSize); +#endif ErrorMessageCode = ErrorCode; } diff --git a/source/adapters/native_cpu/common.cpp b/source/adapters/native_cpu/common.cpp index b956fc8c7a..b9f3737b89 100644 --- a/source/adapters/native_cpu/common.cpp +++ b/source/adapters/native_cpu/common.cpp @@ -19,7 +19,11 @@ thread_local char ErrorMessage[MaxMessageSize]; [[maybe_unused]] void setErrorMessage(const char *pMessage, ur_result_t ErrorCode) { assert(strlen(pMessage) <= MaxMessageSize); - strcpy(ErrorMessage, pMessage); +#if defined(_WIN32) + strncpy_s(ErrorMessage, MaxMessageSize, pMessage, strlen(pMessage)); +#else + strncpy(ErrorMessage, pMessage, MaxMessageSize); +#endif ErrorMessageCode = ErrorCode; } diff --git a/source/adapters/opencl/common.cpp b/source/adapters/opencl/common.cpp index d6e934c68b..7ece6c3393 100644 --- a/source/adapters/opencl/common.cpp +++ b/source/adapters/opencl/common.cpp @@ -19,6 +19,12 @@ thread_local char ErrorMessage[MaxMessageSize]; [[maybe_unused]] void setErrorMessage(const char *Message, int32_t ErrorCode) { assert(strlen(Message) <= cl_adapter::MaxMessageSize); strcpy(cl_adapter::ErrorMessage, Message); +#if defined(_WIN32) + strncpy_s(cl_adapter::ErrorMessage, MaxMessageSize, Message, strlen(Message)); +#else + strncpy(cl_adapter::ErrorMessage, Message, MaxMessageSize); +#endif + ErrorMessageCode = ErrorCode; } } // namespace cl_adapter diff --git a/source/loader/layers/sanitizer/asan_report.cpp b/source/loader/layers/sanitizer/asan_report.cpp index 7843b0f690..7bd8d8bd35 100644 --- a/source/loader/layers/sanitizer/asan_report.cpp +++ b/source/loader/layers/sanitizer/asan_report.cpp @@ -46,11 +46,10 @@ void ReportBadFree(uptr Addr, const StackTrace &stack, if (!AI) { getContext()->logger.always("{} may be allocated on Host Memory", (void *)Addr); + } else { + assert(!AI->IsReleased && "Chunk must be not released"); + PrintAllocateInfo(Addr, AI.get()); } - - assert(AI && !AI->IsReleased && "Chunk must be not released"); - - PrintAllocateInfo(Addr, AI.get()); } void ReportBadContext(uptr Addr, const StackTrace &stack, diff --git a/source/loader/layers/sanitizer/stacktrace.cpp b/source/loader/layers/sanitizer/stacktrace.cpp index ed7f01c9cf..7b3fbbaf40 100644 --- a/source/loader/layers/sanitizer/stacktrace.cpp +++ b/source/loader/layers/sanitizer/stacktrace.cpp @@ -32,7 +32,7 @@ bool Contains(const std::string &s, const char *p) { // Parse back trace information in the following formats: // ([function_name]+function_offset) [offset] -void ParseBacktraceInfo(BacktraceInfo BI, std::string &ModuleName, +void ParseBacktraceInfo(const BacktraceInfo &BI, std::string &ModuleName, uptr &Offset) { // Parse module name size_t End = BI.find_first_of('('); diff --git a/test/conformance/source/environment.cpp b/test/conformance/source/environment.cpp index 006ea09b8b..cc64ab11ea 100644 --- a/test/conformance/source/environment.cpp +++ b/test/conformance/source/environment.cpp @@ -222,7 +222,7 @@ void uur::PlatformEnvironment::selectPlatformFromOptions() { std::stringstream errstr; errstr << "Multiple possible platforms found; please select one of the " "following or set --platforms_count=1:\n"; - for (auto p : platforms_filtered) { + for (const auto &p : platforms_filtered) { errstr << " --backend=" << backend_to_str(p.backend) << " --platform=\"" << p.name << "\"\n"; } @@ -287,7 +287,7 @@ PlatformEnvironment::parsePlatformOptions(int argc, char **argv) { } else if (std::strncmp(arg, "--backend=", sizeof("--backend=") - 1) == 0) { std::string backend_string{&arg[std::strlen("--backend=")]}; - if (!parse_backend(backend_string)) { + if (!parse_backend(std::move(backend_string))) { return options; } } else if (std::strncmp(arg, "--platforms_count=", diff --git a/test/conformance/usm/urUSMFree.cpp b/test/conformance/usm/urUSMFree.cpp index f5502c89a6..a670c26f4b 100644 --- a/test/conformance/usm/urUSMFree.cpp +++ b/test/conformance/usm/urUSMFree.cpp @@ -19,16 +19,16 @@ TEST_P(urUSMFreeTest, SuccessDeviceAlloc) { size_t allocation_size = sizeof(int); ASSERT_SUCCESS(urUSMDeviceAlloc(context, device, nullptr, nullptr, allocation_size, &ptr)); + ASSERT_NE(ptr, nullptr); ur_event_handle_t event = nullptr; uint8_t pattern = 0; - ASSERT_SUCCESS(urEnqueueUSMFill(queue, ptr, sizeof(pattern), &pattern, + EXPECT_SUCCESS(urEnqueueUSMFill(queue, ptr, sizeof(pattern), &pattern, allocation_size, 0, nullptr, &event)); EXPECT_SUCCESS(urQueueFlush(queue)); - ASSERT_SUCCESS(urEventWait(1, &event)); + EXPECT_SUCCESS(urEventWait(1, &event)); - ASSERT_NE(ptr, nullptr); ASSERT_SUCCESS(urUSMFree(context, ptr)); ASSERT_SUCCESS(urEventRelease(event)); } @@ -43,15 +43,15 @@ TEST_P(urUSMFreeTest, SuccessHostAlloc) { size_t allocation_size = sizeof(int); ASSERT_SUCCESS( urUSMHostAlloc(context, nullptr, nullptr, allocation_size, &ptr)); + ASSERT_NE(ptr, nullptr); ur_event_handle_t event = nullptr; uint8_t pattern = 0; - ASSERT_SUCCESS(urEnqueueUSMFill(queue, ptr, sizeof(pattern), &pattern, + EXPECT_SUCCESS(urEnqueueUSMFill(queue, ptr, sizeof(pattern), &pattern, allocation_size, 0, nullptr, &event)); EXPECT_SUCCESS(urQueueFlush(queue)); - ASSERT_SUCCESS(urEventWait(1, &event)); + EXPECT_SUCCESS(urEventWait(1, &event)); - ASSERT_NE(ptr, nullptr); ASSERT_SUCCESS(urUSMFree(context, ptr)); ASSERT_SUCCESS(urEventRelease(event)); } @@ -73,15 +73,15 @@ TEST_P(urUSMFreeTest, SuccessSharedAlloc) { size_t allocation_size = sizeof(int); ASSERT_SUCCESS(urUSMSharedAlloc(context, device, nullptr, nullptr, allocation_size, &ptr)); + ASSERT_NE(ptr, nullptr); ur_event_handle_t event = nullptr; uint8_t pattern = 0; - ASSERT_SUCCESS(urEnqueueUSMFill(queue, ptr, sizeof(pattern), &pattern, + EXPECT_SUCCESS(urEnqueueUSMFill(queue, ptr, sizeof(pattern), &pattern, allocation_size, 0, nullptr, &event)); EXPECT_SUCCESS(urQueueFlush(queue)); - ASSERT_SUCCESS(urEventWait(1, &event)); + EXPECT_SUCCESS(urEventWait(1, &event)); - ASSERT_NE(ptr, nullptr); ASSERT_SUCCESS(urUSMFree(context, ptr)); ASSERT_SUCCESS(urEventRelease(event)); } diff --git a/test/conformance/usm/urUSMSharedAlloc.cpp b/test/conformance/usm/urUSMSharedAlloc.cpp index e543602fbc..021fa6368e 100644 --- a/test/conformance/usm/urUSMSharedAlloc.cpp +++ b/test/conformance/usm/urUSMSharedAlloc.cpp @@ -44,6 +44,7 @@ struct urUSMSharedAllocTest ur_usm_pool_handle_t pool = nullptr; bool usePool = std::get<0>(getParam()).value; + void *ptr = nullptr; }; // The 0 value parameters are not relevant for urUSMSharedAllocTest tests, they @@ -57,7 +58,6 @@ UUR_TEST_SUITE_P( uur::printUSMAllocTestString); TEST_P(urUSMSharedAllocTest, Success) { - void *ptr = nullptr; size_t allocation_size = sizeof(int); ASSERT_SUCCESS(urUSMSharedAlloc(context, device, nullptr, pool, allocation_size, &ptr)); @@ -65,9 +65,9 @@ TEST_P(urUSMSharedAllocTest, Success) { ur_event_handle_t event = nullptr; uint8_t pattern = 0; - ASSERT_SUCCESS(urEnqueueUSMFill(queue, ptr, sizeof(pattern), &pattern, + EXPECT_SUCCESS(urEnqueueUSMFill(queue, ptr, sizeof(pattern), &pattern, allocation_size, 0, nullptr, &event)); - ASSERT_SUCCESS(urEventWait(1, &event)); + EXPECT_SUCCESS(urEventWait(1, &event)); ASSERT_SUCCESS(urUSMFree(context, ptr)); EXPECT_SUCCESS(urEventRelease(event)); @@ -85,7 +85,6 @@ TEST_P(urUSMSharedAllocTest, SuccessWithDescriptors) { ur_usm_desc_t usm_desc{UR_STRUCTURE_TYPE_USM_DESC, &usm_host_desc, /* mem advice flags */ UR_USM_ADVICE_FLAG_DEFAULT, /* alignment */ 0}; - void *ptr = nullptr; size_t allocation_size = sizeof(int); ASSERT_SUCCESS(urUSMSharedAlloc(context, device, &usm_desc, pool, allocation_size, &ptr)); @@ -93,9 +92,9 @@ TEST_P(urUSMSharedAllocTest, SuccessWithDescriptors) { ur_event_handle_t event = nullptr; uint8_t pattern = 0; - ASSERT_SUCCESS(urEnqueueUSMFill(queue, ptr, sizeof(pattern), &pattern, + EXPECT_SUCCESS(urEnqueueUSMFill(queue, ptr, sizeof(pattern), &pattern, allocation_size, 0, nullptr, &event)); - ASSERT_SUCCESS(urEventWait(1, &event)); + EXPECT_SUCCESS(urEventWait(1, &event)); ASSERT_SUCCESS(urUSMFree(context, ptr)); EXPECT_SUCCESS(urEventRelease(event)); @@ -107,7 +106,6 @@ TEST_P(urUSMSharedAllocTest, SuccessWithMultipleAdvices) { /* mem advice flags */ UR_USM_ADVICE_FLAG_SET_READ_MOSTLY | UR_USM_ADVICE_FLAG_BIAS_CACHED, /* alignment */ 0}; - void *ptr = nullptr; size_t allocation_size = sizeof(int); ASSERT_SUCCESS(urUSMSharedAlloc(context, device, &usm_desc, pool, allocation_size, &ptr)); @@ -115,23 +113,21 @@ TEST_P(urUSMSharedAllocTest, SuccessWithMultipleAdvices) { ur_event_handle_t event = nullptr; uint8_t pattern = 0; - ASSERT_SUCCESS(urEnqueueUSMFill(queue, ptr, sizeof(pattern), &pattern, + EXPECT_SUCCESS(urEnqueueUSMFill(queue, ptr, sizeof(pattern), &pattern, allocation_size, 0, nullptr, &event)); - ASSERT_SUCCESS(urEventWait(1, &event)); + EXPECT_SUCCESS(urEventWait(1, &event)); ASSERT_SUCCESS(urUSMFree(context, ptr)); EXPECT_SUCCESS(urEventRelease(event)); } TEST_P(urUSMSharedAllocTest, InvalidNullHandleContext) { - void *ptr = nullptr; ASSERT_EQ_RESULT( UR_RESULT_ERROR_INVALID_NULL_HANDLE, urUSMSharedAlloc(nullptr, device, nullptr, pool, sizeof(int), &ptr)); } TEST_P(urUSMSharedAllocTest, InvalidNullHandleDevice) { - void *ptr = nullptr; ASSERT_EQ_RESULT( UR_RESULT_ERROR_INVALID_NULL_HANDLE, urUSMSharedAlloc(context, nullptr, nullptr, pool, sizeof(int), &ptr)); @@ -144,14 +140,12 @@ TEST_P(urUSMSharedAllocTest, InvalidNullPtrMem) { } TEST_P(urUSMSharedAllocTest, InvalidUSMSize) { - void *ptr = nullptr; ASSERT_EQ_RESULT( UR_RESULT_ERROR_INVALID_USM_SIZE, urUSMSharedAlloc(context, device, nullptr, pool, -1, &ptr)); } TEST_P(urUSMSharedAllocTest, InvalidValueAlignPowerOfTwo) { - void *ptr = nullptr; ur_usm_desc_t desc = {}; desc.stype = UR_STRUCTURE_TYPE_USM_DESC; desc.align = 5; @@ -185,16 +179,15 @@ TEST_P(urUSMSharedAllocAlignmentTest, SuccessAlignedAllocations) { /* mem advice flags */ UR_USM_ADVICE_FLAG_DEFAULT, alignment}; - void *ptr = nullptr; ASSERT_SUCCESS(urUSMSharedAlloc(context, device, &usm_desc, pool, allocation_size, &ptr)); ASSERT_NE(ptr, nullptr); ur_event_handle_t event = nullptr; uint8_t pattern = 0; - ASSERT_SUCCESS(urEnqueueUSMFill(queue, ptr, sizeof(pattern), &pattern, + EXPECT_SUCCESS(urEnqueueUSMFill(queue, ptr, sizeof(pattern), &pattern, allocation_size, 0, nullptr, &event)); - ASSERT_SUCCESS(urEventWait(1, &event)); + EXPECT_SUCCESS(urEventWait(1, &event)); ASSERT_SUCCESS(urUSMFree(context, ptr)); EXPECT_SUCCESS(urEventRelease(event));