Skip to content

Commit

Permalink
[#36] i/o: fix bug in usage of std::isspace
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
lmichaelis committed Nov 17, 2022
1 parent 6bc9967 commit 612b078
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion source/archive/archive_ascii.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ namespace phoenix {
auto line = input.get_line();

// Compatibility fix for binary data in ASCII archives.
while (std::isspace(line[0])) {
while (std::isspace(static_cast<unsigned char>(line[0]))) {
line = line.substr(1);
}

Expand Down
2 changes: 1 addition & 1 deletion source/buffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ namespace phoenix {
(void) get_char(); // ignore the <LF> character itself

if (skip_whitespace) {
auto count = mismatch([](char chr) { return !std::isspace(chr); });
auto count = mismatch([](char chr) { return !std::isspace(static_cast<unsigned char>(chr)); });
if (count == -1) {
position(limit()); // the end of the buffer has been reached
} else {
Expand Down

0 comments on commit 612b078

Please sign in to comment.