Static analyzer bug fixes
[silc.git] / lib / silccore / silcattrs.c
index 796f6255d3318732c0ffbe7ba47191c8d8c165ed..414ecf6e791c49eda5d2c727386aafc78c33cab0 100644 (file)
@@ -4,7 +4,7 @@
 
   Author: Pekka Riikonen <priikone@silcnet.org>
 
-  Copyright (C) 2002 - 2007 Pekka Riikonen
+  Copyright (C) 2002 - 2014 Pekka Riikonen
 
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
@@ -48,15 +48,19 @@ silc_attribute_payload_encode_int(SilcAttribute attribute,
   unsigned char tmp[4], *str = NULL, *ret;
   SilcUInt32 len;
 
+  if (ret_len)
+    *ret_len = 0;
+
   /* Encode according to attribute type */
   if (flags & SILC_ATTRIBUTE_FLAG_VALID) {
-    if (!object && !object_size)
+    if (!object || !object_size)
       return NULL;
 
     switch (attribute) {
 
     case SILC_ATTRIBUTE_USER_INFO:
       {
+#ifdef SILC_DIST_VCARD
        SilcVCard vcard = object;
        if (object_size != sizeof(*vcard))
          return NULL;
@@ -64,6 +68,7 @@ silc_attribute_payload_encode_int(SilcAttribute attribute,
        if (!str)
          return NULL;
        object = str;
+#endif /* SILC_DIST_VCARD */
       }
       break;
 
@@ -287,11 +292,11 @@ SilcAttributePayload silc_attribute_payload_alloc(SilcAttribute attribute,
   attr->data =
     silc_attribute_payload_encode_int(attribute, flags, object,
                                      object_size, &tmp_len);
-  attr->data_len = (SilcUInt16)tmp_len;
   if (!attr->data) {
     silc_free(attr);
     return NULL;
   }
+  attr->data_len = (SilcUInt16)tmp_len;
 
   return attr;
 }
@@ -502,12 +507,14 @@ SilcBool silc_attribute_get_object(SilcAttributePayload payload,
   switch (payload->attribute) {
   case SILC_ATTRIBUTE_USER_INFO:
     {
+#ifdef SILC_DIST_VCARD
       SilcVCard vcard = object;
       if (object_size != sizeof(*vcard))
        break;
       if (!silc_vcard_decode(payload->data, payload->data_len, vcard))
        break;
       ret = TRUE;
+#endif /* SILC_DIST_VCARD */
     }
     break;