From 030b2b5be81dce82589534ddbfcf1f9c530bb354 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Sat, 24 Jul 2010 06:46:58 +0000 Subject: [PATCH] don't dereference empty strings --- include/libtorrent/utf8.hpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/include/libtorrent/utf8.hpp b/include/libtorrent/utf8.hpp index ae8f2a59d..7587ab36e 100644 --- a/include/libtorrent/utf8.hpp +++ b/include/libtorrent/utf8.hpp @@ -50,15 +50,15 @@ namespace libtorrent { // allocate space for worst-case wide.resize(utf8.size()); - wchar_t const* dst_start = &wide[0]; - char const* src_start = &utf8[0]; + wchar_t const* dst_start = wide.c_str(); + char const* src_start = utf8.c_str(); ConversionResult ret; if (sizeof(wchar_t) == sizeof(UTF32)) { ret = ConvertUTF8toUTF32((const UTF8**)&src_start, (const UTF8*)src_start + utf8.size(), (UTF32**)&dst_start, (UTF32*)dst_start + wide.size() , lenientConversion); - wide.resize(dst_start - &wide[0]); + wide.resize(dst_start - wide.c_str()); return ret; } else if (sizeof(wchar_t) == sizeof(UTF16)) @@ -66,7 +66,7 @@ namespace libtorrent ret = ConvertUTF8toUTF16((const UTF8**)&src_start, (const UTF8*)src_start + utf8.size(), (UTF16**)&dst_start, (UTF16*)dst_start + wide.size() , lenientConversion); - wide.resize(dst_start - &wide[0]); + wide.resize(dst_start - wide.c_str()); return ret; } else @@ -79,8 +79,9 @@ namespace libtorrent { // allocate space for worst-case utf8.resize(wide.size() * 6); + if (wide.empty()) return 0; char* dst_start = &utf8[0]; - wchar_t const* src_start = &wide[0]; + wchar_t const* src_start = wide.c_str(); ConversionResult ret; if (sizeof(wchar_t) == sizeof(UTF32)) {