From 496b8d54f05de925f7827785544acbaec35fa356 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Sat, 25 Mar 2023 15:11:34 +0300 Subject: fixes #3454 (Telegram: crash fix) --- libs/libjson/src/JSONNode.cpp | 15 ++++++++++++--- libs/libjson/src/JSONNode.h | 5 +++-- libs/libjson/src/JSONNode.inl | 8 ++++---- libs/win32/libjson.lib | Bin 68786 -> 69346 bytes libs/win64/libjson.lib | Bin 69494 -> 70070 bytes src/mir_app/src/chat_tools.cpp | 9 ++++----- 6 files changed, 23 insertions(+), 14 deletions(-) diff --git a/libs/libjson/src/JSONNode.cpp b/libs/libjson/src/JSONNode.cpp index 1340254b02..daf6e80e2c 100644 --- a/libs/libjson/src/JSONNode.cpp +++ b/libs/libjson/src/JSONNode.cpp @@ -53,9 +53,18 @@ JSONNode nullNode(JSON_NULL); IMPLEMENT_FOR_ALL_TYPES(IMPLEMENT_CTOR) #ifndef JSON_LIBRARY - JSONNode::JSONNode(const json_string & name_t, const json_char * value_t) : internal(internalJSONNode::newInternal()) { - internal -> Set(json_string(value_t)); - internal -> setname(name_t); + JSONNode::JSONNode(const json_string &name_t, const json_char *value_t) : internal(internalJSONNode::newInternal()) + { + internal->Set(json_string(value_t ? value_t : "")); + internal->setname(name_t); + incAllocCount(); + } + + JSONNode::JSONNode(const json_string &name_t, const wchar_t *value_t) : internal(internalJSONNode::newInternal()) + { + T2Utf val(value_t); + internal->Set(json_string(val ? val : "")); + internal->setname(name_t); incAllocCount(); } #endif diff --git a/libs/libjson/src/JSONNode.h b/libs/libjson/src/JSONNode.h index dc69e965ab..a145810854 100644 --- a/libs/libjson/src/JSONNode.h +++ b/libs/libjson/src/JSONNode.h @@ -89,10 +89,11 @@ class LIBJSON_EXPORT JSONNode public: explicit JSONNode(char mytype = JSON_NODE); - #define DECLARE_CTOR(type) JSONNode(const json_string & name_t, type value_t) + #define DECLARE_CTOR(type) JSONNode(const json_string &name_t, type value_t) DECLARE_FOR_ALL_TYPES(DECLARE_CTOR) + JSONNode(const json_string &name_t, const wchar_t *value_t); - JSONNode(const JSONNode & orig); + JSONNode(const JSONNode &orig); ~JSONNode(void); static JSONNode parse(const json_char *str); diff --git a/libs/libjson/src/JSONNode.inl b/libs/libjson/src/JSONNode.inl index 48c1b9ec4f..56dc0b3074 100644 --- a/libs/libjson/src/JSONNode.inl +++ b/libs/libjson/src/JSONNode.inl @@ -17,22 +17,22 @@ inline JSONNode::JSONNode(char mytype) : internal(internalJSONNode::newInternal( (mytype == JSON_NODE), JSON_TEXT("Not a proper JSON type")); incAllocCount(); } -inline JSONNode::JSONNode(const json_string & unparsed) : +inline JSONNode::JSONNode(const json_string &unparsed) : internal(internalJSONNode::newInternal(unparsed)) { //root, specialized because it can only be array or node incAllocCount(); } -inline JSONNode::JSONNode(internalJSONNode * internal_t) : +inline JSONNode::JSONNode(internalJSONNode *internal_t) : internal(internal_t) { //do not increment anything, this is only used in one case and it's already taken care of incAllocCount(); } -inline JSONNode::JSONNode(const JSONNode & orig): internal(orig.internal -> incRef()) +inline JSONNode::JSONNode(const JSONNode &orig) : internal(orig.internal -> incRef()) { incAllocCount(); } //this allows a temp node to simply transfer its contents, even with ref counting off -inline JSONNode::JSONNode(bool, JSONNode & orig): internal(orig.internal) +inline JSONNode::JSONNode(bool, JSONNode &orig) : internal(orig.internal) { orig.internal = 0; incAllocCount(); diff --git a/libs/win32/libjson.lib b/libs/win32/libjson.lib index d49c059aff..efd01d2f85 100644 Binary files a/libs/win32/libjson.lib and b/libs/win32/libjson.lib differ diff --git a/libs/win64/libjson.lib b/libs/win64/libjson.lib index ca2d79bc25..e8c0651a29 100644 Binary files a/libs/win64/libjson.lib and b/libs/win64/libjson.lib differ diff --git a/src/mir_app/src/chat_tools.cpp b/src/mir_app/src/chat_tools.cpp index ee13b56e43..a263cbc35f 100644 --- a/src/mir_app/src/chat_tools.cpp +++ b/src/mir_app/src/chat_tools.cpp @@ -860,24 +860,23 @@ void Chat_Serialize(SESSION_INFO *si) JSONNode pRoleList(JSON_ARRAY); pRoleList.set_name("roles"); for (auto *p = si->pStatuses; p; p = p->next) { JSONNode role; - role << JSONNode("id", p->iStatus) << JSONNode("name", T2Utf(p->pszGroup).get()); + role << JSONNode("id", p->iStatus) << JSONNode("name", p->pszGroup); pRoleList << role; } JSONNode pUserList(JSON_ARRAY); pUserList.set_name("users"); for (auto &it : si->arUsers) { JSONNode user; - user << JSONNode("id", T2Utf(it->pszUID).get()) << JSONNode("nick", T2Utf(it->pszNick).get()) - << JSONNode("role", it->Status) << JSONNode("isMe", it == si->pMe); + user << JSONNode("id", it->pszUID) << JSONNode("nick", it->pszNick) << JSONNode("role", it->Status) << JSONNode("isMe", it == si->pMe); pUserList << user; } JSONNode root; root << pRoleList << pUserList; if (si->ptszName) - root << JSONNode("name", T2Utf(si->ptszName).get()); + root << JSONNode("name", si->ptszName); if (si->ptszTopic) - root << JSONNode("topic", T2Utf(si->ptszTopic).get()); + root << JSONNode("topic", si->ptszTopic); ptrW wszText(json_write(&root)); if (wszText) { -- cgit v1.2.3