From 1ea760ae93caf3a580edc3960d30afaf3c12f58c Mon Sep 17 00:00:00 2001 From: arvidn Date: Mon, 24 Apr 2017 00:44:04 -0400 Subject: [PATCH] fix iconv cast warnings --- include/libtorrent/config.hpp | 6 +++--- src/escape_string.cpp | 6 ++++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/include/libtorrent/config.hpp b/include/libtorrent/config.hpp index 33b9657f4..be22e9c3f 100644 --- a/include/libtorrent/config.hpp +++ b/include/libtorrent/config.hpp @@ -199,7 +199,7 @@ POSSIBILITY OF SUCH DAMAGE. // FreeBSD has a reasonable iconv signature // unless we're on glibc #ifndef __GLIBC__ -# define TORRENT_ICONV_ARG (const char**) +# define TORRENT_ICONV_ARG(x) (x) #endif #endif // __APPLE__ @@ -344,7 +344,7 @@ POSSIBILITY OF SUCH DAMAGE. #define TORRENT_USE_IFCONF 1 #define TORRENT_USE_SYSCTL 1 #define TORRENT_USE_IPV6 0 -#define TORRENT_ICONV_ARG (const char**) +#define TORRENT_ICONV_ARG(x) (x) #define TORRENT_USE_WRITEV 0 #define TORRENT_USE_READV 0 @@ -457,7 +457,7 @@ int snprintf(char* buf, int len, char const* fmt, ...) #endif #ifndef TORRENT_ICONV_ARG -#define TORRENT_ICONV_ARG (char**) +#define TORRENT_ICONV_ARG(x) const_cast(x) #endif #if defined __GNUC__ || defined __clang__ diff --git a/src/escape_string.cpp b/src/escape_string.cpp index c910d446c..2b892e059 100644 --- a/src/escape_string.cpp +++ b/src/escape_string.cpp @@ -514,6 +514,7 @@ namespace libtorrent #endif #if TORRENT_USE_ICONV +namespace { std::string iconv_convert_impl(std::string const& s, iconv_t h) { std::string ret; @@ -525,9 +526,9 @@ namespace libtorrent // posix has a weird iconv signature. implementations // differ on what this signature should be, so we use // a macro to let config.hpp determine it - size_t retval = iconv(h, TORRENT_ICONV_ARG &in, &insize, + size_t retval = iconv(h, TORRENT_ICONV_ARG(&in), &insize, &out, &outsize); - if (retval == (size_t)-1) return s; + if (retval == size_t(-1)) return s; // if this string has an invalid utf-8 sequence in it, don't touch it if (insize != 0) return s; // not sure why this would happen, but it seems to be possible @@ -537,6 +538,7 @@ namespace libtorrent ret.resize(ret.size() - outsize); return ret; } +} // anonymous namespace std::string convert_to_native(std::string const& s) {