From e0c75da266465ad94d3ee22937a69eb1f4f290c8 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Mon, 5 Oct 2020 20:27:31 +0200 Subject: [PATCH] playlist/cue/parser: pass StringView to Feed() --- src/playlist/cue/CueParser.cxx | 6 +++--- src/playlist/cue/CueParser.hxx | 4 +++- src/playlist/plugins/CuePlaylistPlugin.cxx | 1 + test/fuzzer/FuzzCueParser.cxx | 6 ++---- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/playlist/cue/CueParser.cxx b/src/playlist/cue/CueParser.cxx index 89b538422..be367b674 100644 --- a/src/playlist/cue/CueParser.cxx +++ b/src/playlist/cue/CueParser.cxx @@ -21,6 +21,7 @@ #include "tag/ParseName.hxx" #include "util/Alloc.hxx" #include "util/StringStrip.hxx" +#include "util/StringView.hxx" #include "util/CharUtil.hxx" #include @@ -271,12 +272,11 @@ CueParser::Feed2(char *p) noexcept } void -CueParser::Feed(const char *line) noexcept +CueParser::Feed(StringView line) noexcept { assert(!end); - assert(line != nullptr); - char *allocated = xstrdup(line); + char *allocated = xstrndup(line.data, line.size); Feed2(allocated); free(allocated); } diff --git a/src/playlist/cue/CueParser.hxx b/src/playlist/cue/CueParser.hxx index 3e7de2009..ba5e8d6cb 100644 --- a/src/playlist/cue/CueParser.hxx +++ b/src/playlist/cue/CueParser.hxx @@ -27,6 +27,8 @@ #include #include +struct StringView; + class CueParser { enum { /** @@ -104,7 +106,7 @@ public: * Feed a text line from the CUE file into the parser. Call * Get() after this to see if a song has been finished. */ - void Feed(const char *line) noexcept; + void Feed(StringView line) noexcept; /** * Tell the parser that the end of the file has been reached. Call diff --git a/src/playlist/plugins/CuePlaylistPlugin.cxx b/src/playlist/plugins/CuePlaylistPlugin.cxx index d263e0190..f2015a3fe 100644 --- a/src/playlist/plugins/CuePlaylistPlugin.cxx +++ b/src/playlist/plugins/CuePlaylistPlugin.cxx @@ -22,6 +22,7 @@ #include "../SongEnumerator.hxx" #include "../cue/CueParser.hxx" #include "input/TextInputStream.hxx" +#include "util/StringView.hxx" class CuePlaylist final : public SongEnumerator { TextInputStream tis; diff --git a/test/fuzzer/FuzzCueParser.cxx b/test/fuzzer/FuzzCueParser.cxx index 912cabf6a..c0d286b87 100644 --- a/test/fuzzer/FuzzCueParser.cxx +++ b/test/fuzzer/FuzzCueParser.cxx @@ -1,8 +1,6 @@ #include "playlist/cue/CueParser.hxx" #include "util/IterableSplitString.hxx" - -#include -#include +#include "util/StringView.hxx" extern "C" { int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size); @@ -15,7 +13,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) const std::string_view src{(const char *)data, size}; for (const auto line : IterableSplitString(src, '\n')) { - parser.Feed(std::string(line).c_str()); + parser.Feed(line); parser.Get(); }