From c3434fa53d1c83bc65b640951364f842fe6c79f4 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Tue, 16 Oct 2012 00:27:51 +0300 Subject: Fix some signed/unsigned chars issues. --- src/utils/base64.cpp | 2 +- src/utils/copynpaste.cpp | 3 ++- src/utils/stringutils.cpp | 16 +++++++++------- src/utils/stringutils.h | 10 ++++++---- 4 files changed, 18 insertions(+), 13 deletions(-) (limited to 'src/utils') diff --git a/src/utils/base64.cpp b/src/utils/base64.cpp index 52c6821fd..fe3d1cb90 100644 --- a/src/utils/base64.cpp +++ b/src/utils/base64.cpp @@ -50,7 +50,7 @@ unsigned char *php3_base64_encode(const unsigned char *const string, const unsigned char *current = string; int i = 0; unsigned char *const result = static_cast(calloc( - ((length + 3 - length % 3) * 4 / 3 + 1) * sizeof(char), 1)); + ((length + 3 - length % 3) * 4 / 3 + 1) * sizeof(unsigned char), 1)); while (length > 2) { /* keep going until we have less than 24 bits */ diff --git a/src/utils/copynpaste.cpp b/src/utils/copynpaste.cpp index 2b7acc0e1..5d7c32e29 100644 --- a/src/utils/copynpaste.cpp +++ b/src/utils/copynpaste.cpp @@ -196,7 +196,8 @@ bool getDataFromPasteboard(PasteboardRef inPasteboard, for (short dataIndex = 0; dataIndex <= flavorDataSize; dataIndex ++) { - char byte = *(CFDataGetBytePtr(flavorData) + dataIndex); + signed char byte = *(CFDataGetBytePtr( + flavorData) + dataIndex); flavorText[dataIndex] = byte; } diff --git a/src/utils/stringutils.cpp b/src/utils/stringutils.cpp index c201e9593..e28013320 100644 --- a/src/utils/stringutils.cpp +++ b/src/utils/stringutils.cpp @@ -87,7 +87,7 @@ const char *ipToString(const int address) return asciiIP; } -std::string strprintf(char const *const format, ...) +std::string strprintf(const char *const format, ...) { char buf[257]; va_list(args); @@ -161,7 +161,7 @@ int compareStrI(const std::string &a, const std::string &b) } -bool isWordSeparator(const char chr) +bool isWordSeparator(const signed char chr) { return (chr == ' ' || chr == ',' || chr == '.' || chr == '"'); } @@ -229,13 +229,13 @@ const std::string encodeStr(unsigned int value, const unsigned int size) do { - buf += static_cast(value % base + start); + buf += static_cast(value % base + start); value /= base; } while (value); while (buf.length() < size) - buf += static_cast(start); + buf += static_cast(start); return buf; } @@ -393,7 +393,7 @@ void replaceSpecialChars(std::string &text) if (idx + 1 < f && text[f] == ';') { std::string str = " "; - str[0] = static_cast(atoi(text.substr( + str[0] = static_cast(atoi(text.substr( idx, f - idx).c_str())); text = text.substr(0, pos1) + str + text.substr(f + 1); pos1 += 1; @@ -413,7 +413,8 @@ std::string normalize(const std::string &name) return toLower(trim(normalized)); } -std::set splitToIntSet(const std::string &text, const char separator) +std::set splitToIntSet(const std::string &text, + const char separator) { std::set tokens; std::stringstream ss(text); @@ -424,7 +425,8 @@ std::set splitToIntSet(const std::string &text, const char separator) return tokens; } -std::list splitToIntList(const std::string &text, const char separator) +std::list splitToIntList(const std::string &text, + const char separator) { std::list tokens; std::stringstream ss(text); diff --git a/src/utils/stringutils.h b/src/utils/stringutils.h index 582f7f8ed..9355e1720 100644 --- a/src/utils/stringutils.h +++ b/src/utils/stringutils.h @@ -93,7 +93,7 @@ const char *ipToString(const int address); /** * A safe version of sprintf that returns a std::string of the result. */ -std::string strprintf(char const *const format, ...) +std::string strprintf(const char *const format, ...) #ifdef __GNUC__ /* This attribute is nice: it even works through gettext invokation. For example, gcc will complain that strprintf(_("%s"), 42) is ill-formed. */ @@ -136,7 +136,7 @@ int compareStrI(const std::string &a, const std::string &b); /** * Tells wether the character is a word separator. */ -bool isWordSeparator(const char chr); +bool isWordSeparator(const signed char chr); size_t findI(std::string str, std::string subStr); @@ -176,9 +176,11 @@ void replaceSpecialChars(std::string &text); */ std::string normalize(const std::string &name); -std::set splitToIntSet(const std::string &text, const char separator); +std::set splitToIntSet(const std::string &text, + const char separator); -std::list splitToIntList(const std::string &text, const char separator); +std::list splitToIntList(const std::string &text, + const char separator); std::list splitToStringList(const std::string &text, const char separator); -- cgit v1.2.3-60-g2f50