Fix undefined behavior with std::tolower/toupper

main
Duncan Ogilvie 4 months ago
parent 4b6b72874e
commit 559f750c89

@ -681,7 +681,10 @@ static std::string vcpkg_escape_identifier(const std::string &name) {
ch = '-'; ch = '-';
} }
escaped += std::tolower(ch); if (ch >= 'A' && ch <= 'Z') {
ch += ('a' - 'A');
}
escaped += ch;
} }
if (!vcpkg_valid_identifier(escaped)) { if (!vcpkg_valid_identifier(escaped)) {
throw std::runtime_error("The escaped project name '" + escaped + "' is not usable with [vcpkg]"); throw std::runtime_error("The escaped project name '" + escaped + "' is not usable with [vcpkg]");

@ -381,7 +381,8 @@ Project::Project(const Project *parent, const std::string &path, bool build) : p
if (ch == '_') { if (ch == '_') {
normalized += '-'; normalized += '-';
} else if (ch >= 'A' && ch <= 'Z') { } else if (ch >= 'A' && ch <= 'Z') {
normalized += std::tolower(ch); ch += ('a' - 'A');
normalized += ch;
} else if (ch == '-' || (ch >= '0' && ch <= '9') || (ch >= 'a' && ch <= 'z')) { } else if (ch == '-' || (ch >= '0' && ch <= '9') || (ch >= 'a' && ch <= 'z')) {
normalized += ch; normalized += ch;
} else { } else {
@ -532,8 +533,11 @@ Project::Project(const Project *parent, const std::string &path, bool build) : p
key = "URL"; key = "URL";
} else if (hash_algorithms.contains(key)) { } else if (hash_algorithms.contains(key)) {
std::string algo; std::string algo;
for (auto c : key) { for (auto ch : key) {
algo.push_back(std::toupper(c)); if (ch >= 'a' && ch <= 'z') {
ch -= ('a' - 'A');
}
algo.push_back(ch);
} }
key = "URL_HASH"; key = "URL_HASH";
value = algo + "=" + value; value = algo + "=" + value;

Loading…
Cancel
Save