summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2015-03-02 21:48:37 +0100
committerMax Kellermann <max@duempel.org>2015-03-02 21:48:37 +0100
commit87a8a3e22f7d25c88c344cd195bde58d237716a0 (patch)
tree1541669084b0586e2cfb1e82143fecba803b8a06
parente9125ef8e4fc42ba123aa71b5aed6f7e8d05f103 (diff)
PlaylistFile: move memchr() call to class Path
-rw-r--r--src/PlaylistFile.cxx6
-rw-r--r--src/fs/Path.hxx10
2 files changed, 14 insertions, 2 deletions
diff --git a/src/PlaylistFile.cxx b/src/PlaylistFile.cxx
index e22cacfea..7b461e387 100644
--- a/src/PlaylistFile.cxx
+++ b/src/PlaylistFile.cxx
@@ -169,11 +169,13 @@ LoadPlaylistFileInfo(PlaylistInfo &info,
const Path parent_path_fs,
const Path name_fs)
{
+ if (name_fs.HasNewline())
+ return false;
+
const auto *const name_fs_str = name_fs.c_str();
const size_t name_length = name_fs.length();
- if (name_length < ARRAY_SIZE(PLAYLIST_FILE_SUFFIX) ||
- memchr(name_fs_str, '\n', name_length) != nullptr)
+ if (name_length < ARRAY_SIZE(PLAYLIST_FILE_SUFFIX))
return false;
if (!StringEndsWith(name_fs_str, PLAYLIST_FILE_SUFFIX))
diff --git a/src/fs/Path.hxx b/src/fs/Path.hxx
index 8126a668a..962518896 100644
--- a/src/fs/Path.hxx
+++ b/src/fs/Path.hxx
@@ -123,6 +123,16 @@ public:
}
/**
+ * Does the path contain a newline character? (Which is
+ * usually rejected by MPD because its protocol cannot
+ * transfer newline characters).
+ */
+ gcc_pure
+ bool HasNewline() const {
+ return strchr(value, '\n') != nullptr;
+ }
+
+ /**
* Convert the path to UTF-8.
* Returns empty string on error or if this instance is "nulled"
* (#IsNull returns true).