Return NULL if image length is zero. (photo_setter): Warn and don't set
authorHans Petter Jansson <hpj@ximian.com>
Mon, 2 Feb 2004 21:23:09 +0000 (21:23 +0000)
committerHans Petter <hansp@src.gnome.org>
Mon, 2 Feb 2004 21:23:09 +0000 (21:23 +0000)
2004-02-02  Hans Petter Jansson  <hpj@ximian.com>

* libebook/e-contact.c (photo_getter): Return NULL if image length is
zero.
(photo_setter): Warn and don't set photo if image length is zero.

addressbook/ChangeLog
addressbook/libebook/e-contact.c

index 18a2a13..6e3dbf7 100644 (file)
@@ -1,5 +1,11 @@
 2004-02-02  Hans Petter Jansson  <hpj@ximian.com>
 
+       * libebook/e-contact.c (photo_getter): Return NULL if image length is
+       zero.
+       (photo_setter): Warn and don't set photo if image length is zero.
+
+2004-02-02  Hans Petter Jansson  <hpj@ximian.com>
+
        * libebook/e-contact.c (photo_setter): Handle NULL.
        (fn_setter): Handle NULL.
        (n_setter): Handle NULL.
index 19c05d0..a30a6b4 100644 (file)
@@ -361,8 +361,12 @@ photo_getter (EContact *contact, EVCardAttribute *attr)
 
                if (values && values->data) {
                        GString *s = values->data;
-                       EContactPhoto *photo = g_new (EContactPhoto, 1);
+                       EContactPhoto *photo;
 
+                       if (!s->len)
+                               return NULL;
+
+                       photo = g_new (EContactPhoto, 1);
                        photo->length = s->len;
                        photo->data = g_malloc (photo->length);
                        memcpy (photo->data, s->str, photo->length);
@@ -384,6 +388,8 @@ photo_setter (EContact *contact, EVCardAttribute *attr, void *data)
        if (!photo)
                return;
 
+       g_return_if_fail (photo->length > 0);
+
        e_vcard_attribute_add_param_with_value (attr,
                                                e_vcard_attribute_param_new (EVC_ENCODING),
                                                "b");