From 942e458bf5267402843965876216d44d69c34d03 Mon Sep 17 00:00:00 2001 From: Alhuda Khan Date: Sun, 11 Oct 2026 23:54:28 +0530 Subject: [PATCH] cast to unsigned char for ctype calls on signed-char input --- src/Client.cpp | 2 +- src/IRCNetwork.cpp | 2 +- src/Message.cpp | 5 +++-- src/User.cpp | 5 +++-- src/ZNCString.cpp | 4 ++-- 5 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/Client.cpp b/src/Client.cpp index acb7e8b6..aa9c0896 100644 --- a/src/Client.cpp +++ b/src/Client.cpp @@ -792,7 +792,7 @@ bool CClient::IsValidIdentifier(const CString& sIdentifier) { const char* p = sIdentifier.c_str(); while (*p) { - if (*p != '_' && *p != '-' && !isalnum(*p)) { + if (*p != '_' && *p != '-' && !isalnum((unsigned char)*p)) { return false; } diff --git a/src/IRCNetwork.cpp b/src/IRCNetwork.cpp index 767210dd..def087fd 100644 --- a/src/IRCNetwork.cpp +++ b/src/IRCNetwork.cpp @@ -117,7 +117,7 @@ bool CIRCNetwork::IsValidNetwork(const CString& sNetwork) { const char* p = sNetwork.c_str(); while (*p) { - if (*p != '_' && *p != '-' && !isalnum(*p)) { + if (*p != '_' && *p != '-' && !isalnum((unsigned char)*p)) { return false; } diff --git a/src/Message.cpp b/src/Message.cpp index 71369a7f..fec944f8 100644 --- a/src/Message.cpp +++ b/src/Message.cpp @@ -254,8 +254,9 @@ void CMessage::InitTime() { } void CMessage::InitType() { - if (m_sCommand.length() == 3 && isdigit(m_sCommand[0]) && - isdigit(m_sCommand[1]) && isdigit(m_sCommand[2])) { + if (m_sCommand.length() == 3 && isdigit((unsigned char)m_sCommand[0]) && + isdigit((unsigned char)m_sCommand[1]) && + isdigit((unsigned char)m_sCommand[2])) { m_eType = Type::Numeric; } else if (m_sCommand.Equals("PRIVMSG")) { CString sParam = GetParam(1); diff --git a/src/User.cpp b/src/User.cpp index ded6d19a..8eb50b17 100644 --- a/src/User.cpp +++ b/src/User.cpp @@ -921,7 +921,8 @@ bool CUser::IsValidUserName(const CString& sUsername) { } while (*p) { - if (*p != '@' && *p != '.' && *p != '-' && *p != '_' && !isalnum(*p)) { + if (*p != '@' && *p != '.' && *p != '-' && *p != '_' && + !isalnum((unsigned char)*p)) { return false; } @@ -1402,7 +1403,7 @@ bool CUser::SetStatusPrefix(const CString& s) { bool CUser::SetLanguage(const CString& s) { // They look like ru-RU for (char c : s) { - if (isalpha(c) || c == '-' || c == '_') { + if (isalpha((unsigned char)c) || c == '-' || c == '_') { } else { return false; } diff --git a/src/ZNCString.cpp b/src/ZNCString.cpp index c30469b9..c61d96ce 100644 --- a/src/ZNCString.cpp +++ b/src/ZNCString.cpp @@ -220,7 +220,7 @@ bool CString::WildCmp(const CString& sWild, CaseSensitivity cs) const { CString& CString::MakeUpper() { for (char& c : *this) { // TODO use unicode - c = (char)toupper(c); + c = (char)toupper((unsigned char)c); } return *this; @@ -229,7 +229,7 @@ CString& CString::MakeUpper() { CString& CString::MakeLower() { for (char& c : *this) { // TODO use unicode - c = (char)tolower(c); + c = (char)tolower((unsigned char)c); } return *this;