Skip to content

Commit

Permalink
[L0] Add nullopt check before init results access
Browse files Browse the repository at this point in the history
ZeInitResult and ZeInitDriversResult could potentially be uninitialized,
resulting in undefined behavior when accessed.
  • Loading branch information
kswiecicki committed Nov 28, 2024
1 parent db83117 commit 2943768
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions source/adapters/level_zero/adapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -385,8 +385,10 @@ ur_adapter_handle_t_::ur_adapter_handle_t_()
}
}

if (*GlobalAdapter->ZeInitResult == ZE_RESULT_SUCCESS ||
*GlobalAdapter->ZeInitDriversResult == ZE_RESULT_SUCCESS) {
if ((GlobalAdapter->ZeInitResult != std::nullopt &&
*GlobalAdapter->ZeInitResult == ZE_RESULT_SUCCESS) ||
(GlobalAdapter->ZeInitDriversResult != std::nullopt &&
*GlobalAdapter->ZeInitDriversResult == ZE_RESULT_SUCCESS)) {
GlobalAdapter->ZeResult = ZE_RESULT_SUCCESS;
} else {
GlobalAdapter->ZeResult = ZE_RESULT_ERROR_UNINITIALIZED;
Expand Down

0 comments on commit 2943768

Please sign in to comment.