fs/Charset: don't allow nullptr arguments

This commit is contained in:
Max Kellermann 2013-10-17 22:39:06 +02:00
parent 080ee87e07
commit f951e5356b
3 changed files with 8 additions and 7 deletions

View File

@ -79,8 +79,7 @@ GetFSCharset()
std::string std::string
PathToUTF8(const char *path_fs) PathToUTF8(const char *path_fs)
{ {
if (path_fs == nullptr) assert(path_fs != nullptr);
return std::string();
GIConv conv = g_iconv_open("utf-8", fs_charset.c_str()); GIConv conv = g_iconv_open("utf-8", fs_charset.c_str());
if (conv == reinterpret_cast<GIConv>(-1)) if (conv == reinterpret_cast<GIConv>(-1))
@ -107,6 +106,8 @@ PathToUTF8(const char *path_fs)
char * char *
PathFromUTF8(const char *path_utf8) PathFromUTF8(const char *path_utf8)
{ {
assert(path_utf8 != nullptr);
return g_convert(path_utf8, -1, return g_convert(path_utf8, -1,
fs_charset.c_str(), "utf-8", fs_charset.c_str(), "utf-8",
nullptr, nullptr, nullptr); nullptr, nullptr, nullptr);

View File

@ -37,13 +37,13 @@ SetFSCharset(const char *charset);
/** /**
* Convert the path to UTF-8. * Convert the path to UTF-8.
* Returns empty string on error or if #path_fs is null pointer. * Returns empty string on error.
*/ */
gcc_pure gcc_pure gcc_nonnull_all
std::string std::string
PathToUTF8(const char *path_fs); PathToUTF8(const char *path_fs);
gcc_malloc gcc_malloc gcc_nonnull_all
char * char *
PathFromUTF8(const char *path_utf8); PathFromUTF8(const char *path_utf8);

View File

@ -123,10 +123,10 @@ public:
* Convert a UTF-8 C string to a #Path instance. * Convert a UTF-8 C string to a #Path instance.
* Returns return a "nulled" instance on error. * Returns return a "nulled" instance on error.
*/ */
gcc_pure gcc_pure gcc_nonnull_all
static Path FromUTF8(const char *path_utf8); static Path FromUTF8(const char *path_utf8);
gcc_pure gcc_pure gcc_nonnull_all
static Path FromUTF8(const char *path_utf8, Error &error); static Path FromUTF8(const char *path_utf8, Error &error);
/** /**