small fixes
authorVolker Birk <vb@pep-project.org>
Sun, 13 Nov 2016 19:16:05 +0100
changeset 21233bddd7ba879
parent 211 3e6efc641a02
child 213 d32175cbbdbe
small fixes
pEp_utility.cpp
     1.1 --- a/pEp_utility.cpp	Sun Nov 13 16:28:45 2016 +0100
     1.2 +++ b/pEp_utility.cpp	Sun Nov 13 19:16:05 2016 +0100
     1.3 @@ -8,6 +8,9 @@
     1.4          pEp_identity_cpp::pEp_identity_cpp(const ::pEp_identity *_ident)
     1.5              : me(false)
     1.6          {
     1.7 +			if (!_ident)
     1.8 +				return;
     1.9 +
    1.10              if (_ident->address)
    1.11                  address = _ident->address;
    1.12              if (_ident->fpr)
    1.13 @@ -23,7 +26,10 @@
    1.14          pEp_identity_cpp::pEp_identity_cpp(const pEpIdentity *_ident)
    1.15              : me(false)
    1.16          {
    1.17 -            if (_ident->Address)
    1.18 +			if (!_ident)
    1.19 +				return;
    1.20 +
    1.21 +			if (_ident->Address)
    1.22                  address = utf8_string(_ident->Address);
    1.23              if (_ident->Fpr)
    1.24                  fpr = utf8_string(_ident->Fpr);
    1.25 @@ -76,6 +82,8 @@
    1.26          void copy_identity(pEpIdentity * ident_s, const pEp_identity * ident)
    1.27          {
    1.28              assert(ident_s);
    1.29 +			if (!ident_s)
    1.30 +				throw invalid_argument("ident_s");
    1.31  
    1.32              ::memset(ident_s, 0, sizeof(pEpIdentity));
    1.33              if (ident) {
    1.34 @@ -164,15 +172,21 @@
    1.35  
    1.36          template<> Blob *from_C< Blob *, bloblist_t >(bloblist_t *tl)
    1.37          {
    1.38 +			assert(tl);
    1.39 +
    1.40              CComSafeArray<BYTE> sa;
    1.41 -            sa.Create(tl->size);
    1.42 -
    1.43 -            if (tl->size) {
    1.44 -                char *data;
    1.45 -                SafeArrayAccessData(sa, (void **) &data);
    1.46 -                memcpy(data, tl->value, tl->size);
    1.47 -                SafeArrayUnaccessData(sa);
    1.48 -            }
    1.49 +			if (tl) {
    1.50 +				sa.Create(tl->size);
    1.51 +				if (tl->size) {
    1.52 +					char *data;
    1.53 +					SafeArrayAccessData(sa, (void **)&data);
    1.54 +					memcpy(data, tl->value, tl->size);
    1.55 +					SafeArrayUnaccessData(sa);
    1.56 +				}
    1.57 +			}
    1.58 +			else {
    1.59 +				sa.Create((ULONG)0);
    1.60 +			}
    1.61  
    1.62              Blob *_blob = new Blob();
    1.63  
    1.64 @@ -452,7 +466,14 @@
    1.65  
    1.66          stringpair_t *new_stringpair(StringPair *fld)
    1.67          {
    1.68 -            stringpair_t *pair = ::new_stringpair(str(fld->Name), str(fld->Value));
    1.69 +			stringpair_t *pair;
    1.70 +
    1.71 +			if (!fld) {
    1.72 +				pair = ::new_stringpair(NULL, NULL);
    1.73 +			}
    1.74 +			else {
    1.75 +				pair = ::new_stringpair(str(fld->Name), str(fld->Value));
    1.76 +			}
    1.77              if (pair == NULL)
    1.78                  throw bad_alloc();
    1.79  
    1.80 @@ -511,6 +532,8 @@
    1.81          ::message * text_message_to_C(TextMessage *msg)
    1.82          {
    1.83              assert(msg);
    1.84 +			if (!msg)
    1.85 +				throw invalid_argument("msg");
    1.86  
    1.87              ::message * msg2 = new_message((PEP_msg_direction) msg->Dir);
    1.88              if (msg2 == NULL)
    1.89 @@ -548,9 +571,10 @@
    1.90  		}
    1.91  
    1.92  		void clear_opt_field_array(LPSAFEARRAY* opt_field_array) {
    1.93 -			SafeArrayDestroy(*opt_field_array);
    1.94 -			//memset(*opt_field_array, 0, sizeof(SAFEARRAY*));
    1.95 -			*opt_field_array = NULL;
    1.96 +			if (opt_field_array){
    1.97 +				SafeArrayDestroy(*opt_field_array);
    1.98 +				*opt_field_array = NULL;
    1.99 +			}
   1.100  		}
   1.101      }
   1.102  }