[SYCL] Coverity: avoid std::string_view(nullptr) in sycl-trace collectors#22111
Merged
Merged
Conversation
slawekptak
approved these changes
May 26, 2026
Contributor
|
@intel/llvm-gatekeepers please consider merging |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related to #18506.
Summary
Coverity reported potential null pointer issues in SYCL trace collectors where
std::string_viewwas constructed directly fromstd::getenv(...).If the environment variable is not set, this can result in
std::string_view(nullptr)(UB).Affected CIDs from the issue:
CID
437235:llvm/sycl/tools/sycl-trace/sycl_trace_collector.cpp
Line 138 in f9a7cc8
CID
442884:llvm/sycl/tools/sycl-trace/ur_trace_collector.cpp
Line 91 in f9a7cc8
CID
440717:llvm/sycl/tools/sycl-trace/verification_collector.cpp
Line 27 in f9a7cc8
CID
437184:llvm/sycl/tools/sycl-trace/ze_trace_collector.cpp
Line 311 in f9a7cc8
What changed
Replaced direct construction from
std::getenv(...)with null-safe handling:Applied in:
sycl/tools/sycl-trace/sycl_trace_collector.cppsycl/tools/sycl-trace/ur_trace_collector.cppsycl/tools/sycl-trace/verification_collector.cppsycl/tools/sycl-trace/ze_trace_collector.cppsycl/tools/sycl-trace/cuda_trace_collector.cpp(same pattern, proactively fixed)Behavior impact
No functional change is intended for valid env values (
classic,verbose,compact).When
SYCL_TRACE_PRINT_FORMATis unset, behavior is now explicitly safe and well-defined.