playlist/extm3u: allocate Tag instance on the stack
Automate the life cycle, making the code safer.
This commit is contained in:
parent
676d8bb624
commit
1f90e3ce7f
|
@ -67,7 +67,7 @@ extm3u_open_stream(InputStream &is)
|
||||||
*
|
*
|
||||||
* @param line the rest of the input line after the colon
|
* @param line the rest of the input line after the colon
|
||||||
*/
|
*/
|
||||||
static Tag *
|
static Tag
|
||||||
extm3u_parse_tag(const char *line)
|
extm3u_parse_tag(const char *line)
|
||||||
{
|
{
|
||||||
long duration;
|
long duration;
|
||||||
|
@ -77,7 +77,7 @@ extm3u_parse_tag(const char *line)
|
||||||
duration = strtol(line, &endptr, 10);
|
duration = strtol(line, &endptr, 10);
|
||||||
if (endptr[0] != ',')
|
if (endptr[0] != ',')
|
||||||
/* malformed line */
|
/* malformed line */
|
||||||
return NULL;
|
return Tag();
|
||||||
|
|
||||||
if (duration < 0)
|
if (duration < 0)
|
||||||
/* 0 means unknown duration */
|
/* 0 means unknown duration */
|
||||||
|
@ -87,7 +87,7 @@ extm3u_parse_tag(const char *line)
|
||||||
if (*name == 0 && duration == 0)
|
if (*name == 0 && duration == 0)
|
||||||
/* no information available; don't allocate a tag
|
/* no information available; don't allocate a tag
|
||||||
object */
|
object */
|
||||||
return NULL;
|
return Tag();
|
||||||
|
|
||||||
TagBuilder tag;
|
TagBuilder tag;
|
||||||
tag.SetTime(duration);
|
tag.SetTime(duration);
|
||||||
|
@ -98,26 +98,23 @@ extm3u_parse_tag(const char *line)
|
||||||
if (*name != 0)
|
if (*name != 0)
|
||||||
tag.AddItem(TAG_NAME, name);
|
tag.AddItem(TAG_NAME, name);
|
||||||
|
|
||||||
return tag.CommitNew();
|
return tag.Commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
DetachedSong *
|
DetachedSong *
|
||||||
ExtM3uPlaylist::NextSong()
|
ExtM3uPlaylist::NextSong()
|
||||||
{
|
{
|
||||||
Tag *tag = NULL;
|
Tag tag;
|
||||||
std::string line;
|
std::string line;
|
||||||
const char *line_s;
|
const char *line_s;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
if (!tis.ReadLine(line)) {
|
if (!tis.ReadLine(line))
|
||||||
delete tag;
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
|
||||||
|
|
||||||
line_s = line.c_str();
|
line_s = line.c_str();
|
||||||
|
|
||||||
if (StringStartsWith(line_s, "#EXTINF:")) {
|
if (StringStartsWith(line_s, "#EXTINF:")) {
|
||||||
delete tag;
|
|
||||||
tag = extm3u_parse_tag(line_s + 8);
|
tag = extm3u_parse_tag(line_s + 8);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -125,9 +122,7 @@ ExtM3uPlaylist::NextSong()
|
||||||
line_s = strchug_fast(line_s);
|
line_s = strchug_fast(line_s);
|
||||||
} while (line_s[0] == '#' || *line_s == 0);
|
} while (line_s[0] == '#' || *line_s == 0);
|
||||||
|
|
||||||
DetachedSong *song = new DetachedSong(line_s, std::move(*tag));
|
return new DetachedSong(line_s, std::move(tag));
|
||||||
delete tag;
|
|
||||||
return song;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char *const extm3u_suffixes[] = {
|
static const char *const extm3u_suffixes[] = {
|
||||||
|
|
Loading…
Reference in New Issue