Skip to content

Commit

Permalink
remove all trailing null characters in model name
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiud committed Aug 3, 2024
1 parent 939547c commit 3a9b5dc
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/cpuidpp/cpuidpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,7 @@ struct ExtractChar
ExtractChar<T, N - 1, Size>::fill(value, out);

const auto ch = static_cast<char>((value >> (Index * 8)) & 0xff);

// If this is the last character in the sequence corresponding to a
// binary zero, discard it.
if (Index + 1 != Size || ch != '\0') {
out.append(1, ch);
}
out.append(1, ch);
}
};

Expand Down Expand Up @@ -454,6 +449,15 @@ struct CPUIDImpl

using std::placeholders::_1;

// Trim null on the right
std::string::size_type pos = model.find_last_not_of('\0');

if (pos != std::string::npos) {
// pos is pointing to a valid character we do not want to
// discard. Advance to the next one.
model.erase(pos + 1);
}

// Trim whitespace left and right
model.erase(model.begin(), std::find_if_not(model.begin(), model.end(),
std::bind(std::isspace<char>, _1, std::locale::classic())));
Expand Down

0 comments on commit 3a9b5dc

Please sign in to comment.