y500 / libtorrent

Automatically exported from code.google.com/p/libtorrent
0 stars 0 forks source link

[Win] convert_[to|from]_native return string with '\0' #641

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
With TORRENT_WINDOWS enabled, convert_[to|from]_native return string with '\0' 
as last character, so
convert_from_native("1") + "2" == "1\02"

Patch:

Index: escape_string.cpp
===================================================================
--- escape_string.cpp   (revision 10033)
+++ escape_string.cpp   (working copy)
@@ -592,6 +592,7 @@
                ret.resize(ws.size() * 4 + 1);
                std::size_t size = WideCharToMultiByte(CP_ACP, 0, ws.c_str(), -1, &ret[0], ret.size(), NULL, NULL);
                if (size == std::size_t(-1)) return s;
+               if (size != 0 && ret[size - 1] == '\0') --size;
                ret.resize(size);
                return ret;
        }
@@ -602,6 +603,7 @@
                ws.resize(s.size() + 1);
                std::size_t size = MultiByteToWideChar(CP_ACP, 0, s.c_str(), -1, &ws[0], ws.size());
                if (size == std::size_t(-1)) return s;
+               if (size != 0 && ws[size - 1] == '\0') --size;
                ws.resize(size);
                std::string ret;
                libtorrent::wchar_utf8(ws, ret);

Original issue reported on code.google.com by fl.lllj on 24 Jun 2014 at 8:03

GoogleCodeExporter commented 8 years ago
thanks for the report! fixed with unit test.

Original comment by arvid.no...@gmail.com on 25 Jun 2014 at 5:44