GothicKit / ZenKit

A re-implementation of file formats used by the early 2000's ZenGin
http://zk.gothickit.dev/
MIT License
44 stars 9 forks source link

Assetion in `std::string buffer::get_line(bool skip_whitespace)`, with MSVC build #36

Closed Try closed 1 year ago

Try commented 1 year ago

изображение sorry for awful screenshot :)

Offended code:

    std::string buffer::get_line(bool skip_whitespace) {
        ...
        if (skip_whitespace) {
            auto count = mismatch([](char chr) { return !std::isspace(chr); }); // <--
            if (count == -1) {
                position(limit()); // the end of the buffer has been reached
            } else {
                position(position() + count);
            }
        }

        return tmp;
    }

char can be signed on some C++ implementations, and have negative values. Issue was hit, when parsing world mesh in steam-eng version of gothic2

lmichaelis commented 1 year ago

Hm interesting. To my knowledge isspace is supposed to take an int anyways (see cppreference)? Regardless I'll see if I can reproduce on MinGW on Linux so that I can actually see what's going on here :)

Update: I missed the most crucial part

The behavior is undefined if the value of ch is not representable as unsigned char and is not equal to EOF.

I will implement a fix later.

lmichaelis commented 1 year ago

Fixed in 69cd380.