mapper: allocate the result of map_directory_child_fs(), map_song_fs()

Don't use fixed stack buffers.
This commit is contained in:
Max Kellermann
2009-01-02 10:48:55 +01:00
parent 72255d580e
commit daf7c3db5a
6 changed files with 72 additions and 53 deletions

View File

@@ -108,11 +108,11 @@ map_directory_fs(const struct directory *directory)
return map_uri_fs(dirname);
}
const char *
map_directory_child_fs(const struct directory *directory, const char *name,
char *buffer)
char *
map_directory_child_fs(const struct directory *directory, const char *name)
{
char *parent_fs;
char buffer[MPD_PATH_MAX];
char *parent_fs, *path;
/* check for invalid or unauthorized base names */
if (*name == 0 || strchr(name, '/') != NULL ||
@@ -124,21 +124,22 @@ map_directory_child_fs(const struct directory *directory, const char *name,
return NULL;
name = utf8_to_fs_charset(buffer, name);
pfx_dir(buffer, name, strlen(name),
parent_fs, strlen(parent_fs));
path = g_build_filename(parent_fs, name, NULL);
g_free(parent_fs);
return buffer;
return path;
}
const char *
map_song_fs(const struct song *song, char *buffer)
char *
map_song_fs(const struct song *song)
{
char buffer[MPD_PATH_MAX];
assert(song_is_file(song));
if (song_in_database(song))
return map_directory_child_fs(song->parent, song->url, buffer);
return map_directory_child_fs(song->parent, song->url);
else
return utf8_to_fs_charset(buffer, song->url);
return g_strdup(utf8_to_fs_charset(buffer, song->url));
}
const char *