Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Try opened this issue Nov 13, 2022 · 2 comments
Closed
Assignees
Labels
bug Something isn't working
Milestone

Comments

@Try
Copy link
Contributor

Try commented Nov 13, 2022

изображение
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 lmichaelis added the bug Something isn't working label Nov 14, 2022
@lmichaelis lmichaelis added this to the v1.1.0 milestone Nov 14, 2022
@lmichaelis
Copy link
Member

lmichaelis commented Nov 14, 2022

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 added a commit that referenced this issue Nov 14, 2022
Before, `std::isspace` was passed regular, possibly signed `char`s.
This is not supported by `std::isspace`, however, and causes incorrect
behaviour on some systems. As per cppreference:

>  The behavior [of `std::isspace`] is undefined if the value of ch
>  is not representable as unsigned char and is not equal to EOF.

-> see https://en.cppreference.com/w/cpp/string/byte/isspace
@lmichaelis lmichaelis self-assigned this Nov 14, 2022
@lmichaelis lmichaelis added the awaiting verification The problem has been fixed, though external verification of this fix is required label Nov 14, 2022
@lmichaelis
Copy link
Member

Fixed in 69cd380.

@Try Try closed this as completed Nov 15, 2022
@lmichaelis lmichaelis removed the awaiting verification The problem has been fixed, though external verification of this fix is required label Nov 16, 2022
lmichaelis added a commit that referenced this issue Nov 17, 2022
Before, `std::isspace` was passed regular, possibly signed `char`s.
This is not supported by `std::isspace`, however, and causes incorrect
behaviour on some systems. As per cppreference:

>  The behavior [of `std::isspace`] is undefined if the value of ch
>  is not representable as unsigned char and is not equal to EOF.

-> see https://en.cppreference.com/w/cpp/string/byte/isspace

(cherry picked from commit 69cd380)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants