Skip to content

Commit

Permalink
- fix crash with safe_str to wrap nlohman
Browse files Browse the repository at this point in the history
  • Loading branch information
polymonster committed Feb 23, 2024
1 parent f2503d6 commit 133b904
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions app/code/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,19 @@ void* user_data_thread(void* userdata)
return nullptr;
}

inline Str safe_str(nlohmann::json& j, const c8* key, const Str& default_value)
{
if(j.contains(key))
{
if(j[key].is_string())
{
return ((std::string)j[key]).c_str();
}
}

return default_value;
}

void* releases_view_loader(void* userdata)
{
// get view from userdata
Expand Down Expand Up @@ -919,20 +932,13 @@ void* releases_view_loader(void* userdata)
auto release = releases_registry[entry.index];

// simple info
view->releases.artist[ri] = release["artist"];
view->releases.title[ri] = release["title"];
view->releases.link[ri] = release["link"];
view->releases.label[ri] = release["label"];
view->releases.cat[ri] = release["cat"];
view->releases.store[ri] = release["store"];

//
if(release.contains("label_link")) {
view->releases.label_link[ri] = release["label_link"];
}
else {
view->releases.label_link[ri] = "";
}
view->releases.artist[ri] = safe_str(release, "artist", "");
view->releases.title[ri] = safe_str(release, "title", "");
view->releases.link[ri] = safe_str(release, "link", "");
view->releases.label[ri] = safe_str(release, "label", "");
view->releases.cat[ri] = safe_str(release, "cat", "");
view->releases.store[ri] = safe_str(release, "store", "");
view->releases.label_link[ri] = safe_str(release, "label_link", "");

// clear
view->releases.artwork_filepath[ri] = "";
Expand Down

0 comments on commit 133b904

Please sign in to comment.