Skip to content

[Coverity] Potential nullptr dereference in various sycl tools #18506

@AlexeySachkov

Description

@AlexeySachkov

See Coverity issues at https://scan.coverity.com/projects/intel-llvm?tab=analysis_settings

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"));


The problem here is that string_view(nullptr) behavior is not defined.
string_veiw(const chatT *str) constructor has a precondition that [str, str + char_traits<charT>::length(str)) is a valid range (string.view.cons.2).

length is defined by char.traits.require as:

Returns: the smallest i such that X​::​eq(p[i],charT()) is true.

When there is no such i when p is nullptr. See also p0903r0

string_view(nullptr) constructor is explicitly deleted in C++23: cppreference.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions