Skip to content

Invalid use of std::isspace in StringUtils.h #1874

@SRHMorris

Description

@SRHMorris

StringUtils.h contains potentially undefined behaviour when checking for whitespace.

const auto it = std::find_if(str.begin(), str.end(), [](char ch) { return !std::isspace(ch); });

and

std::find_if(str.rbegin(), str.rend(), [](char ch) { return !std::isspace(ch); });

Both should be converted to something equivalent to std::isspace(static_cast<unsigned char>(ch)).

From cppreference:

Like all other functions from cctype, the behavior of std::isspace is undefined if the argument's value is neither representable as unsigned char nor equal to EOF. To use these functions safely with plain chars (or signed chars), the argument should first be converted to unsigned char

I'm hitting asserts when loading a specific ICC profile for a virtual display in these functions when compiling on windows with MSVC:

Debug Assertion Failed!

Program: <redacted>
File: minkernel\crts\ucrt\src\appcrt\convert\isctype.cpp
Line: 36

Expression: c >= -1 && c <= 255

For information on how your program can cause an assertion
failure, see the Visual C++ documentation on asserts.

(Press Retry to debug the application)

Metadata

Metadata

Assignees

No one assigned

    Labels

    good first issueStandard label for new developers to locate good issues to tackle to learn about OCIO development.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions