From 43a3a91b0372ad4f51e57b3a9d861f1d2bc8a649 Mon Sep 17 00:00:00 2001 From: HanishKVC Date: Tue, 7 May 2024 11:44:25 +0530 Subject: [PATCH] ChatON: Cleanup/Refine initial go at tmpl_apply_ex_capi --- common/chaton.hpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/common/chaton.hpp b/common/chaton.hpp index aa9ade4aa..74a9a38fb 100644 --- a/common/chaton.hpp +++ b/common/chaton.hpp @@ -608,7 +608,10 @@ inline int32_t chaton_tmpl_apply_ex_capi( std::string taggedMsgs; std::string types; std::vector lens; - int32_t taggedLength = chaton_tmpl_apply_ex(tmpl, vMsgs, taggedMsgs, types, lens, alertAssistantAtEnd); + if (!chaton_tmpl_apply_ex(tmpl, vMsgs, taggedMsgs, types, lens, alertAssistantAtEnd)) { + return -1; + } + int32_t taggedLength = taggedMsgs.size(); if (taggedLength <= 0) { return taggedLength; } @@ -616,9 +619,13 @@ inline int32_t chaton_tmpl_apply_ex_capi( strlcpy(dest, taggedMsgs.c_str(), destLength); } if (*pNumParts > 0) { - strlcpy(partTypes, types.c_str(), *pNumParts); - for(int i=0; i < *pNumParts; i++) { - partLengths[i] = lens[i]; + if (partTypes != nullptr) { + strlcpy(partTypes, types.c_str(), *pNumParts); + } + if (partLengths != nullptr) { + for(int i=0; i < *pNumParts; i++) { + partLengths[i] = lens[i]; + } } } *pNumParts = types.length();