Commit 7d4de718 authored by Max Kellermann's avatar Max Kellermann

sticker/SongSticker: use AllocatedString for concatenation

parent e1c16d78
...@@ -22,12 +22,13 @@ ...@@ -22,12 +22,13 @@
#include "Database.hxx" #include "Database.hxx"
#include "song/LightSong.hxx" #include "song/LightSong.hxx"
#include "db/Interface.hxx" #include "db/Interface.hxx"
#include "util/Alloc.hxx" #include "util/AllocatedString.hxx"
#include "util/ScopeExit.hxx"
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
using std::string_view_literals::operator""sv;
std::string std::string
sticker_song_get_value(StickerDatabase &db, sticker_song_get_value(StickerDatabase &db,
const LightSong &song, const char *name) const LightSong &song, const char *name)
...@@ -116,17 +117,15 @@ sticker_song_find(StickerDatabase &sticker_database, const Database &db, ...@@ -116,17 +117,15 @@ sticker_song_find(StickerDatabase &sticker_database, const Database &db,
data.func = func; data.func = func;
data.user_data = user_data; data.user_data = user_data;
char *allocated; AllocatedString allocated;
data.base_uri = base_uri; data.base_uri = base_uri;
if (*data.base_uri != 0) if (*data.base_uri != 0) {
/* append slash to base_uri */ /* append slash to base_uri */
data.base_uri = allocated = allocated = AllocatedString{std::string_view{data.base_uri}, "/"sv};
xstrcatdup(data.base_uri, "/"); data.base_uri = allocated.c_str();
else } else {
/* searching in root directory - no trailing slash */ /* searching in root directory - no trailing slash */
allocated = nullptr; }
AtScopeExit(allocated) { free(allocated); };
data.base_uri_length = strlen(data.base_uri); data.base_uri_length = strlen(data.base_uri);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment