update: check return values
Nearly all mapper functions can fail and will then return NULL. Add checks to all callers.
This commit is contained in:
parent
d8e877e335
commit
a5f8d4386c
@ -31,20 +31,25 @@
|
|||||||
static void decodeStart(void)
|
static void decodeStart(void)
|
||||||
{
|
{
|
||||||
struct song *song = dc.next_song;
|
struct song *song = dc.next_song;
|
||||||
|
char buffer[MPD_PATH_MAX];
|
||||||
|
const char *uri;
|
||||||
struct decoder decoder;
|
struct decoder decoder;
|
||||||
int ret;
|
int ret;
|
||||||
bool close_instream = true;
|
bool close_instream = true;
|
||||||
struct input_stream inStream;
|
struct input_stream inStream;
|
||||||
struct decoder_plugin *plugin = NULL;
|
struct decoder_plugin *plugin = NULL;
|
||||||
char path_max_fs[MPD_PATH_MAX];
|
|
||||||
|
|
||||||
if (song_is_file(song))
|
if (song_is_file(song))
|
||||||
map_song_fs(song, path_max_fs);
|
uri = map_song_fs(song, buffer);
|
||||||
else
|
else
|
||||||
song_get_url(song, path_max_fs);
|
uri = song_get_url(song, buffer);
|
||||||
|
if (uri == NULL) {
|
||||||
|
dc.error = DECODE_ERROR_FILE;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
dc.current_song = dc.next_song; /* NEED LOCK */
|
dc.current_song = dc.next_song; /* NEED LOCK */
|
||||||
if (!input_stream_open(&inStream, path_max_fs)) {
|
if (!input_stream_open(&inStream, uri)) {
|
||||||
dc.error = DECODE_ERROR_FILE;
|
dc.error = DECODE_ERROR_FILE;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -98,7 +103,7 @@ static void decodeStart(void)
|
|||||||
|
|
||||||
/* if that fails, try suffix matching the URL: */
|
/* if that fails, try suffix matching the URL: */
|
||||||
if (plugin == NULL) {
|
if (plugin == NULL) {
|
||||||
const char *s = getSuffix(path_max_fs);
|
const char *s = getSuffix(uri);
|
||||||
next = 0;
|
next = 0;
|
||||||
while ((plugin = decoder_plugin_from_suffix(s, next++))) {
|
while ((plugin = decoder_plugin_from_suffix(s, next++))) {
|
||||||
if (plugin->stream_decode == NULL)
|
if (plugin->stream_decode == NULL)
|
||||||
@ -129,7 +134,7 @@ static void decodeStart(void)
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
unsigned int next = 0;
|
unsigned int next = 0;
|
||||||
const char *s = getSuffix(path_max_fs);
|
const char *s = getSuffix(uri);
|
||||||
while ((plugin = decoder_plugin_from_suffix(s, next++))) {
|
while ((plugin = decoder_plugin_from_suffix(s, next++))) {
|
||||||
if (!plugin->stream_types & INPUT_PLUGIN_STREAM_FILE)
|
if (!plugin->stream_types & INPUT_PLUGIN_STREAM_FILE)
|
||||||
continue;
|
continue;
|
||||||
@ -142,8 +147,7 @@ static void decodeStart(void)
|
|||||||
input_stream_close(&inStream);
|
input_stream_close(&inStream);
|
||||||
close_instream = false;
|
close_instream = false;
|
||||||
decoder.plugin = plugin;
|
decoder.plugin = plugin;
|
||||||
ret = plugin->file_decode(&decoder,
|
ret = plugin->file_decode(&decoder, uri);
|
||||||
path_max_fs);
|
|
||||||
break;
|
break;
|
||||||
} else if (plugin->stream_decode != NULL) {
|
} else if (plugin->stream_decode != NULL) {
|
||||||
decoder.plugin = plugin;
|
decoder.plugin = plugin;
|
||||||
|
@ -52,5 +52,6 @@ playlist_print_uri(FILE *file, const char *uri)
|
|||||||
else
|
else
|
||||||
s = utf8_to_fs_charset(tmp, uri);
|
s = utf8_to_fs_charset(tmp, uri);
|
||||||
|
|
||||||
fprintf(file, "%s\n", s);
|
if (s != NULL)
|
||||||
|
fprintf(file, "%s\n", s);
|
||||||
}
|
}
|
||||||
|
13
src/song.c
13
src/song.c
@ -94,28 +94,31 @@ song_free(struct song *song)
|
|||||||
bool
|
bool
|
||||||
song_file_update(struct song *song)
|
song_file_update(struct song *song)
|
||||||
{
|
{
|
||||||
|
char buffer[MPD_PATH_MAX];
|
||||||
|
const char *path_fs;
|
||||||
struct decoder_plugin *plugin;
|
struct decoder_plugin *plugin;
|
||||||
unsigned int next = 0;
|
unsigned int next = 0;
|
||||||
char abs_path[MPD_PATH_MAX];
|
|
||||||
struct stat st;
|
struct stat st;
|
||||||
|
|
||||||
assert(song_is_file(song));
|
assert(song_is_file(song));
|
||||||
|
|
||||||
map_song_fs(song, abs_path);
|
path_fs = map_song_fs(song, buffer);
|
||||||
|
if (path_fs == NULL)
|
||||||
|
return false;
|
||||||
|
|
||||||
if (song->tag != NULL) {
|
if (song->tag != NULL) {
|
||||||
tag_free(song->tag);
|
tag_free(song->tag);
|
||||||
song->tag = NULL;
|
song->tag = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (stat(abs_path, &st) < 0 || !S_ISREG(st.st_mode))
|
if (stat(path_fs, &st) < 0 || !S_ISREG(st.st_mode))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
song->mtime = st.st_mtime;
|
song->mtime = st.st_mtime;
|
||||||
|
|
||||||
while (song->tag == NULL &&
|
while (song->tag == NULL &&
|
||||||
(plugin = hasMusicSuffix(abs_path, next++)))
|
(plugin = hasMusicSuffix(path_fs, next++)))
|
||||||
song->tag = plugin->tag_dup(abs_path);
|
song->tag = plugin->tag_dup(path_fs);
|
||||||
|
|
||||||
return song->tag != NULL;
|
return song->tag != NULL;
|
||||||
}
|
}
|
||||||
|
@ -206,9 +206,13 @@ static int
|
|||||||
stat_directory_child(const struct directory *parent, const char *name,
|
stat_directory_child(const struct directory *parent, const char *name,
|
||||||
struct stat *st)
|
struct stat *st)
|
||||||
{
|
{
|
||||||
char path_fs[MPD_PATH_MAX];
|
char buffer[MPD_PATH_MAX];
|
||||||
|
const char *path_fs;
|
||||||
|
|
||||||
|
path_fs = map_directory_child_fs(parent, name, buffer);
|
||||||
|
if (path_fs == NULL)
|
||||||
|
return -1;
|
||||||
|
|
||||||
map_directory_child_fs(parent, name, path_fs);
|
|
||||||
return stat(path_fs, st);
|
return stat(path_fs, st);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user