Skip to content

[SYCL] Coverity: avoid std::string_view(nullptr) in sycl-trace collectors#22111

Merged
KornevNikita merged 1 commit into
intel:syclfrom
crystarm:fix/sycl-getenv-string-view
May 26, 2026
Merged

[SYCL] Coverity: avoid std::string_view(nullptr) in sycl-trace collectors#22111
KornevNikita merged 1 commit into
intel:syclfrom
crystarm:fix/sycl-getenv-string-view

Conversation

@crystarm
Copy link
Copy Markdown
Contributor

@crystarm crystarm commented May 25, 2026

Related to #18506.

Summary

Coverity reported potential null pointer issues in SYCL trace collectors where std::string_view was constructed directly from std::getenv(...).
If the environment variable is not set, this can result in std::string_view(nullptr) (UB).

Affected CIDs from the issue:
CID 437235:

std::string_view PrinterType(std::getenv("SYCL_TRACE_PRINT_FORMAT"));

CID 442884:

std::string_view PrinterType(std::getenv("SYCL_TRACE_PRINT_FORMAT"));

CID 440717:

std::string_view PrinterType(std::getenv("SYCL_TRACE_PRINT_FORMAT"));

CID 437184:

std::string_view PrinterType(std::getenv("SYCL_TRACE_PRINT_FORMAT"));

What changed

Replaced direct construction from std::getenv(...) with null-safe handling:

const char *PrinterTypeEnv = std::getenv("SYCL_TRACE_PRINT_FORMAT");
std::string_view PrinterType = PrinterTypeEnv ? PrinterTypeEnv : "";

Applied in:

  • sycl/tools/sycl-trace/sycl_trace_collector.cpp
  • sycl/tools/sycl-trace/ur_trace_collector.cpp
  • sycl/tools/sycl-trace/verification_collector.cpp
  • sycl/tools/sycl-trace/ze_trace_collector.cpp
  • sycl/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_FORMAT is unset, behavior is now explicitly safe and well-defined.

@crystarm crystarm requested a review from a team as a code owner May 25, 2026 15:31
@crystarm crystarm requested a review from slawekptak May 25, 2026 15:31
@crystarm crystarm marked this pull request as draft May 25, 2026 15:32
@crystarm crystarm marked this pull request as ready for review May 25, 2026 15:37
@sys-ce-bb
Copy link
Copy Markdown
Contributor

@intel/llvm-gatekeepers please consider merging

@KornevNikita KornevNikita linked an issue May 26, 2026 that may be closed by this pull request
@KornevNikita KornevNikita merged commit 5068046 into intel:sycl May 26, 2026
31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Coverity] Potential nullptr dereference in various sycl tools

4 participants