aboutsummaryrefslogtreecommitdiffstats
path: root/alc/backends
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2021-12-31 16:04:10 -0800
committerChris Robinson <[email protected]>2021-12-31 20:23:30 -0800
commit1337f050dd3654a80403967434939584c87b62e9 (patch)
tree0e17c94a8093342d8f3ebab2e2acc9f0f7bde28b /alc/backends
parentad9c2d77c8cc1a4169c908cbaef606aa7b0b2635 (diff)
Avoid a static-sized char array on the stack
Diffstat (limited to 'alc/backends')
-rw-r--r--alc/backends/pipewire.cpp38
1 files changed, 22 insertions, 16 deletions
diff --git a/alc/backends/pipewire.cpp b/alc/backends/pipewire.cpp
index 75e092bd..3ff02790 100644
--- a/alc/backends/pipewire.cpp
+++ b/alc/backends/pipewire.cpp
@@ -844,28 +844,34 @@ int MetadataProxy::propertyCallback(uint32_t id, const char *key, const char *ty
if(spa_json_enter_object(&it[0], &it[1]) <= 0)
return 0;
- char k[128]{};
- while(spa_json_get_string(&it[1], k, sizeof(k)-1) > 0)
+ auto get_json_string = [](spa_json *iter)
{
- if(std::strcmp(k, "name") == 0)
+ al::optional<std::string> str;
+
+ const char *val{};
+ int len{spa_json_next(iter, &val)};
+ if(len <= 0) return str;
+
+ str.emplace().resize(static_cast<uint>(len), '\0');
+ if(spa_json_parse_string(val, len, &str->front()) <= 0)
+ str.reset();
+ else while(!str->empty() && str->back() == '\0')
+ str->pop_back();
+ return str;
+ };
+ while(auto propKey = get_json_string(&it[1]))
+ {
+ if(*propKey == "name")
{
- const char *name{};
- int len{spa_json_next(&it[1], &name)};
- if(len <= 0) break;
-
- std::string nametmp;
- nametmp.resize(static_cast<uint>(len)+1, '\0');
- if(spa_json_parse_string(name, len, &nametmp[0]) <= 0)
- break;
- while(!nametmp.empty() && nametmp.back() == '\0')
- nametmp.pop_back();
+ auto propValue = get_json_string(&it[1]);
+ if(!propValue) break;
TRACE("Got default %s device \"%s\"\n", isCapture ? "capture" : "playback",
- nametmp.c_str());
+ propValue->c_str());
if(!isCapture)
- DefaultSinkDevice = nametmp;
+ DefaultSinkDevice = std::move(*propValue);
else
- DefaultSourceDevice = nametmp;
+ DefaultSourceDevice = std::move(*propValue);
}
else
{