From 7d84e4900fa8f4ef96e8cf4bb67b76be7902e840 Mon Sep 17 00:00:00 2001 From: Sadie Powell Date: Sun, 4 Apr 2021 23:42:15 +0100 Subject: Fix a ton of pedantic compiler warnings. --- src/hashcomp.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'src/hashcomp.cpp') diff --git a/src/hashcomp.cpp b/src/hashcomp.cpp index ff12328b3..37158bb06 100644 --- a/src/hashcomp.cpp +++ b/src/hashcomp.cpp @@ -89,8 +89,8 @@ unsigned const char ascii_case_insensitive_map[256] = { bool irc::equals(const std::string& s1, const std::string& s2) { - const unsigned char* n1 = (const unsigned char*)s1.c_str(); - const unsigned char* n2 = (const unsigned char*)s2.c_str(); + const unsigned char* n1 = reinterpret_cast(s1.c_str()); + const unsigned char* n2 = reinterpret_cast(s2.c_str()); for (; *n1 && *n2; n1++, n2++) if (national_case_insensitive_map[*n1] != national_case_insensitive_map[*n2]) return false; @@ -111,7 +111,9 @@ size_t irc::find(const std::string& haystack, const std::string& needle) bool found = true; for (size_t npos = 0; npos < needle.length(); ++npos) { - if (national_case_insensitive_map[(unsigned char)needle[npos]] != national_case_insensitive_map[(unsigned char)haystack[hpos + npos]]) + unsigned char unpos = needle[npos]; + unsigned char uhpos = haystack[hpos + npos]; + if (national_case_insensitive_map[unpos] != national_case_insensitive_map[uhpos]) { // Uh-oh, characters at the current haystack position don't match. found = false; @@ -131,15 +133,14 @@ size_t irc::find(const std::string& haystack, const std::string& needle) bool irc::insensitive_swo::operator()(const std::string& a, const std::string& b) const { - const unsigned char* charmap = national_case_insensitive_map; std::string::size_type asize = a.size(); std::string::size_type bsize = b.size(); std::string::size_type maxsize = std::min(asize, bsize); for (std::string::size_type i = 0; i < maxsize; i++) { - unsigned char A = charmap[(unsigned char)a[i]]; - unsigned char B = charmap[(unsigned char)b[i]]; + unsigned char A = national_case_insensitive_map[static_cast(a[i])]; + unsigned char B = national_case_insensitive_map[static_cast(b[i])]; if (A > B) return false; else if (A < B) @@ -157,8 +158,8 @@ size_t irc::insensitive::operator()(const std::string &s) const * This avoids a copy to use hash */ size_t t = 0; - for (std::string::const_iterator x = s.begin(); x != s.end(); ++x) /* ++x not x++, as its faster */ - t = 5 * t + national_case_insensitive_map[(unsigned char)*x]; + for (const auto& c : s) + t = 5 * t + national_case_insensitive_map[static_cast(c)]; return t; } -- cgit v1.3.1-10-gc9f91