From ae08d4475c2fdb49c6f718b8fdc9e40b215dca8a Mon Sep 17 00:00:00 2001 From: wshon Date: Sun, 24 Mar 2024 09:01:38 +0800 Subject: [PATCH] fix: exception when artist is empty (#16) Co-authored-by: wshon --- ncmcrypt.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/ncmcrypt.cpp b/ncmcrypt.cpp index 3dc9617..a27ede1 100644 --- a/ncmcrypt.cpp +++ b/ncmcrypt.cpp @@ -94,12 +94,18 @@ NeteaseMusicMetadata::NeteaseMusicMetadata(cJSON *raw) artistLen = cJSON_GetArraySize(swap); i = 0; - for (i = 0; i < artistLen - 1; i++) + for (i = 0; i < artistLen; i++) { - mArtist += std::string(cJSON_GetStringValue(cJSON_GetArrayItem(cJSON_GetArrayItem(swap, i), 0))); - mArtist += "/"; + auto artist = cJSON_GetArrayItem(swap, i); + if (cJSON_GetArraySize(artist) > 0) + { + if (!mArtist.empty()) + { + mArtist += "/"; + } + mArtist += std::string(cJSON_GetStringValue(cJSON_GetArrayItem(artist, 0))); + } } - mArtist += std::string(cJSON_GetStringValue(cJSON_GetArrayItem(cJSON_GetArrayItem(swap, i), 0))); } swap = cJSON_GetObjectItem(raw, "bitrate");