safer
authorVolker Birk <vb@pep-project.org>
Sun, 31 May 2015 19:31:19 +0200
changeset 396fc5cc7a167c
parent 38 d314ed57180c
child 40 dfb59114debe
safer
CpEpEngine.cpp
pEp_utility.h
pEp_utitlity.cpp
utf8_helper.cpp
     1.1 --- a/CpEpEngine.cpp	Sun May 31 18:26:37 2015 +0200
     1.2 +++ b/CpEpEngine.cpp	Sun May 31 19:31:19 2015 +0200
     1.3 @@ -899,17 +899,16 @@
     1.4      assert(rating);
     1.5  
     1.6      ::message *_src = text_message_to_C(src);
     1.7 -    ::message *msg_dst;
     1.8 +    ::message *msg_dst = NULL;
     1.9      ::stringlist_t *_keylist;
    1.10      ::PEP_color _rating;
    1.11  
    1.12      PEP_STATUS status = ::decrypt_message(get_session(), _src, &msg_dst, &_keylist, &_rating);
    1.13 -    free_message(_src);
    1.14 -    if (status != PEP_STATUS_OK)
    1.15 -        return FAIL(L"decrypt message failed");
    1.16 +    ::free_message(_src);
    1.17  
    1.18      if (msg_dst) {
    1.19          text_message_from_C(dst, msg_dst);
    1.20 +        ::free_message(msg_dst);
    1.21      }
    1.22  
    1.23      if (_keylist) {
     2.1 --- a/pEp_utility.h	Sun May 31 18:26:37 2015 +0200
     2.2 +++ b/pEp_utility.h	Sun May 31 19:31:19 2015 +0200
     2.3 @@ -38,18 +38,21 @@
     2.4          void copy_identity(pEp_identity_s * ident_s, const pEp_identity * ident);
     2.5          ::pEp_identity *new_identity(const pEp_identity_s * ident);
     2.6  
     2.7 +        static LPTYPELIB pTypelib = NULL;
     2.8 +
     2.9          template< class UDType > static IRecordInfo *getRecordInfo()
    2.10          {
    2.11              LPTYPEINFO pTypeInfo = NULL;
    2.12 -            LPTYPELIB pTypelib = NULL;
    2.13              LPSAFEARRAY psaUDType = NULL;
    2.14              IRecordInfo* pRecInfo = NULL;
    2.15  
    2.16              // Fetch the IRecordInfo interface describing the UDT
    2.17 -            HRESULT hr = LoadRegTypeLib(LIBID_pEpCOMServerAdapterLib, 1, 0, GetUserDefaultLCID(), &pTypelib);
    2.18 -            assert(SUCCEEDED(hr) && pTypelib);
    2.19 +            if (pTypelib == NULL)
    2.20 +                LoadRegTypeLib(LIBID_pEpCOMServerAdapterLib, 1, 0, GetUserDefaultLCID(), &pTypelib);
    2.21  
    2.22 -            hr = pTypelib->GetTypeInfoOfGuid(__uuidof(UDType), &pTypeInfo);
    2.23 +            assert(pTypelib);
    2.24 +
    2.25 +            HRESULT hr = pTypelib->GetTypeInfoOfGuid(__uuidof(UDType), &pTypeInfo);
    2.26              assert(SUCCEEDED(hr) && pTypeInfo);
    2.27              hr = GetRecordInfoFromTypeInfo(pTypeInfo, &pRecInfo);
    2.28              assert(SUCCEEDED(hr) && pRecInfo);
     3.1 --- a/pEp_utitlity.cpp	Sun May 31 18:26:37 2015 +0200
     3.2 +++ b/pEp_utitlity.cpp	Sun May 31 19:31:19 2015 +0200
     3.3 @@ -189,6 +189,9 @@
     3.4  
     3.5          template< class T2, class T > SAFEARRAY * array_from_C(T *tl)
     3.6          {
     3.7 +            if (tl == NULL)
     3.8 +                return newSafeArray<T2>(0);
     3.9 +
    3.10              int len = length<T>(tl);
    3.11  
    3.12              LPSAFEARRAY sa = newSafeArray<T2>(len);
    3.13 @@ -206,7 +209,8 @@
    3.14          template<> pEp_identity_s from_C< pEp_identity_s, pEp_identity >(pEp_identity *tl)
    3.15          {
    3.16              pEp_identity_s _ident;
    3.17 -            copy_identity(&_ident, tl);
    3.18 +            if (tl)
    3.19 +                copy_identity(&_ident, tl);
    3.20              return _ident;
    3.21          }
    3.22  
    3.23 @@ -218,15 +222,18 @@
    3.24          template<> pEp_identity_s *from_C< pEp_identity_s *, identity_list >(identity_list *il)
    3.25          {
    3.26              pEp_identity_s *ident = new pEp_identity_s();
    3.27 -            copy_identity(ident, il->ident);
    3.28 +            if (il)
    3.29 +                copy_identity(ident, il->ident);
    3.30              return ident;
    3.31          }
    3.32  
    3.33          template<> opt_field *from_C< opt_field *, stringpair_list_t >(stringpair_list_t * sp)
    3.34          {
    3.35              opt_field *fld = new opt_field();
    3.36 -            fld->name = bstr(sp->value->key);
    3.37 -            fld->value = bstr(sp->value->value);
    3.38 +            if (sp) {
    3.39 +                fld->name = bstr(sp->value->key);
    3.40 +                fld->value = bstr(sp->value->value);
    3.41 +            }
    3.42              return fld;
    3.43          }
    3.44  
    3.45 @@ -256,8 +263,10 @@
    3.46              msg2->longmsg = bstr(msg->longmsg);
    3.47              msg2->longmsg_formatted = bstr(msg->longmsg_formatted);
    3.48              msg2->attachments = array_from_C<blob, bloblist_t>(msg->attachments);
    3.49 -            msg2->sent = mktime(msg->sent);
    3.50 -            msg2->recv = mktime(msg->recv);
    3.51 +            if (msg->sent)
    3.52 +                msg2->sent = mktime(msg->sent);
    3.53 +            if (msg->recv)
    3.54 +                msg2->recv = mktime(msg->recv);
    3.55              msg2->from = identity_s(msg->from);
    3.56              msg2->to = array_from_C<pEp_identity_s, identity_list>(msg->to);
    3.57              msg2->recv_by = identity_s(msg->recv_by);
    3.58 @@ -438,7 +447,7 @@
    3.59          {
    3.60              assert(msg);
    3.61  
    3.62 -            ::message * msg2 = new_message((PEP_msg_direction) msg->dir, NULL, NULL, NULL);
    3.63 +            ::message * msg2 = new_message((PEP_msg_direction) msg->dir);
    3.64              if (msg2 == NULL)
    3.65                  throw bad_alloc();
    3.66  
     4.1 --- a/utf8_helper.cpp	Sun May 31 18:26:37 2015 +0200
     4.2 +++ b/utf8_helper.cpp	Sun May 31 19:31:19 2015 +0200
     4.3 @@ -75,7 +75,8 @@
     4.4  
     4.5          _bstr_t utf16_bstr(string str)
     4.6          {
     4.7 -            return _bstr_t(utf16_string(str).c_str());
     4.8 +            wstring wstr = utf16_string(str);
     4.9 +            return _bstr_t(wstr.c_str());
    4.10          }
    4.11  
    4.12          CComSafeArray<BSTR> string_array(const ::stringlist_t *stringlist)