2004-09-07 Lutz Mueller <lutz@users.sourceforge.net>
authorLutz Mueller <lutz.s.mueller@gmail.com>
Tue, 7 Sep 2004 20:46:31 +0000 (22:46 +0200)
committerLutz Mueller <lutz.s.mueller@gmail.com>
Tue, 7 Sep 2004 20:46:31 +0000 (22:46 +0200)
* libexif/exif-entry.c: Use calloc. Hint by Jan Patera
  <patera@pictview.com>.

ChangeLog
libexif/exif-entry.c

index 1d758ca..16cf245 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 2004-09-07  Lutz Mueller <lutz@users.sourceforge.net>
 
+       * libexif/exif-entry.c: Use calloc. Hint by Jan Patera
+         <patera@pictview.com>.
+
+2004-09-07  Lutz Mueller <lutz@users.sourceforge.net>
+
        * libexif/olympus
        * libexif/pentax: Fix typo and wrong logic introduced during my
          last changes. Thanks to Jan Patera
index 8f8f111..209909a 100644 (file)
@@ -44,15 +44,15 @@ struct _ExifEntryPrivate
 ExifLog *exif_data_get_log (ExifData *);
 
 static void *
-exif_entry_malloc (ExifEntry *e, unsigned int i)
+exif_entry_alloc (ExifEntry *e, unsigned int i)
 {
        void *d;
        ExifLog *l = NULL;
 
        if (!i) return NULL;
 
-       /* This is the only call to malloc in this file. */
-       d = malloc (i);
+       /* This is the only call to calloc in this file. */
+       d = calloc (i, 1);
        if (d) return d;
 
        if (e && e->parent && e->parent->parent)
@@ -67,12 +67,10 @@ exif_entry_new (void)
 {
        ExifEntry *e = NULL;
 
-       e = exif_entry_malloc (e, sizeof (ExifEntry));
+       e = exif_entry_alloc (e, sizeof (ExifEntry));
        if (!e) return NULL;
-       memset (e, 0, sizeof (ExifEntry));
-       e->priv = exif_entry_malloc (e, sizeof (ExifEntryPrivate));
+       e->priv = exif_entry_alloc (e, sizeof (ExifEntryPrivate));
        if (!e->priv) { free (e); return NULL; }
-       memset (e->priv, 0, sizeof (ExifEntryPrivate));
        e->priv->ref_count = 1;
 
        return (e);
@@ -844,8 +842,7 @@ exif_entry_initialize (ExifEntry *e, ExifTag tag)
                e->components = 1;
                e->format = EXIF_FORMAT_LONG;
                e->size = exif_format_get_size (e->format) * e->components;
-               e->data = exif_entry_malloc (e, e->size);
-               if (e->data) memset (e->data, 0, e->size);
+               e->data = exif_entry_alloc (e, e->size);
                break;
 
        /* SHORT, 1 component, no default */
@@ -873,7 +870,7 @@ exif_entry_initialize (ExifEntry *e, ExifTag tag)
                e->components = 1;
                e->format = EXIF_FORMAT_SHORT;
                e->size = exif_format_get_size (e->format) * e->components;
-               e->data = exif_entry_malloc (e, e->size);
+               e->data = exif_entry_alloc (e, e->size);
                exif_set_short (e->data, o, 0);
                break;
 
@@ -884,7 +881,7 @@ exif_entry_initialize (ExifEntry *e, ExifTag tag)
                e->components = 1;
                e->format = EXIF_FORMAT_SHORT;
                e->size = exif_format_get_size (e->format) * e->components;
-               e->data = exif_entry_malloc (e, e->size);
+               e->data = exif_entry_alloc (e, e->size);
                exif_set_short (e->data, o, 1);
                break;
 
@@ -894,7 +891,7 @@ exif_entry_initialize (ExifEntry *e, ExifTag tag)
                e->components = 1;
                e->format = EXIF_FORMAT_SHORT;
                e->size = exif_format_get_size (e->format) * e->components;
-               e->data = exif_entry_malloc (e, e->size);
+               e->data = exif_entry_alloc (e, e->size);
                exif_set_short (e->data, o, 2);
                break;
 
@@ -903,7 +900,7 @@ exif_entry_initialize (ExifEntry *e, ExifTag tag)
                e->components = 1;
                e->format = EXIF_FORMAT_SHORT;
                e->size = exif_format_get_size (e->format) * e->components;
-               e->data = exif_entry_malloc (e, e->size);
+               e->data = exif_entry_alloc (e, e->size);
                exif_set_short (e->data, o, 3);
                break;
 
@@ -911,7 +908,7 @@ exif_entry_initialize (ExifEntry *e, ExifTag tag)
                e->components = 3;
                e->format = EXIF_FORMAT_SHORT;
                e->size = exif_format_get_size (e->format) * e->components;
-               e->data = exif_entry_malloc (e, e->size);
+               e->data = exif_entry_alloc (e, e->size);
                if (!e->data) break;
                exif_set_short (e->data, o, 8);
                exif_set_short (
@@ -925,7 +922,7 @@ exif_entry_initialize (ExifEntry *e, ExifTag tag)
                e->components = 2;
                e->format = EXIF_FORMAT_SHORT;
                e->size = exif_format_get_size (e->format) * e->components;
-               e->data = exif_entry_malloc (e, e->size);
+               e->data = exif_entry_alloc (e, e->size);
                if (!e->data) break;
                exif_set_short (e->data, o, 2);
                exif_set_short (
@@ -940,8 +937,7 @@ exif_entry_initialize (ExifEntry *e, ExifTag tag)
                e->components = 1;
                e->format = EXIF_FORMAT_SRATIONAL;
                e->size = exif_format_get_size (e->format) * e->components;
-               e->data = exif_entry_malloc (e, e->size);
-               if (e->data) memset (e->data, 0, e->size);
+               e->data = exif_entry_alloc (e, e->size);
                break;
 
        /* RATIONAL, 1 component, no default */
@@ -961,8 +957,7 @@ exif_entry_initialize (ExifEntry *e, ExifTag tag)
                e->components = 1;
                e->format = EXIF_FORMAT_RATIONAL;
                e->size = exif_format_get_size (e->format) * e->components;
-               e->data = exif_entry_malloc (e, e->size);
-               if (e->data) memset (e->data, 0, e->size);
+               e->data = exif_entry_alloc (e, e->size);
                break;
 
        /* RATIONAL, 1 component, default 72/1 */
@@ -971,7 +966,7 @@ exif_entry_initialize (ExifEntry *e, ExifTag tag)
                e->components = 1;
                e->format = EXIF_FORMAT_RATIONAL;
                e->size = exif_format_get_size (e->format) * e->components;
-               e->data = exif_entry_malloc (e, e->size);
+               e->data = exif_entry_alloc (e, e->size);
                r.numerator = 72;
                r.denominator = 1;
                exif_set_rational (e->data, o, r);
@@ -982,8 +977,7 @@ exif_entry_initialize (ExifEntry *e, ExifTag tag)
                e->components = 2;
                e->format = EXIF_FORMAT_RATIONAL;
                e->size = exif_format_get_size (e->format) * e->components;
-               e->data = exif_entry_malloc (e, e->size);
-               if (e->data) memset (e->data, 0, e->size);
+               e->data = exif_entry_alloc (e, e->size);
                break;
 
        /* RATIONAL, 6 components */
@@ -991,7 +985,7 @@ exif_entry_initialize (ExifEntry *e, ExifTag tag)
                e->components = 6;
                e->format = EXIF_FORMAT_RATIONAL;
                e->size = exif_format_get_size (e->format) * e->components;
-               e->data = exif_entry_malloc (e, e->size);
+               e->data = exif_entry_alloc (e, e->size);
                if (!e->data) break;
                r.denominator = 1;
                r.numerator = 0;
@@ -1022,7 +1016,7 @@ exif_entry_initialize (ExifEntry *e, ExifTag tag)
                e->components = 20;
                e->format = EXIF_FORMAT_ASCII;
                e->size = exif_format_get_size (e->format) * e->components;
-               e->data = exif_entry_malloc (e, e->size);
+               e->data = exif_entry_alloc (e, e->size);
                if (!e->data) break;
                snprintf ((char *) e->data, e->size,
                          "%04i:%02i:%02i %02i:%02i:%02i",
@@ -1047,7 +1041,7 @@ exif_entry_initialize (ExifEntry *e, ExifTag tag)
                e->components = strlen ("[None]") + 1;
                e->format = EXIF_FORMAT_ASCII;
                e->size = exif_format_get_size (e->format) * e->components;
-               e->data = exif_entry_malloc (e, e->size);
+               e->data = exif_entry_alloc (e, e->size);
                if (!e->data) break;
                strncpy (e->data, "[None]", e->size);
                break;
@@ -1055,7 +1049,7 @@ exif_entry_initialize (ExifEntry *e, ExifTag tag)
                e->components = (strlen ("[None]") + 1) * 2;
                e->format = EXIF_FORMAT_ASCII;
                e->size = exif_format_get_size (e->format) * e->components;
-               e->data = exif_entry_malloc (e, e->size);
+               e->data = exif_entry_alloc (e, e->size);
                if (!e->data) break;
                strcpy (e->data +                     0, "[None]");
                strcpy (e->data + strlen ("[None]") + 1, "[None]");
@@ -1075,7 +1069,7 @@ exif_entry_initialize (ExifEntry *e, ExifTag tag)
                e->components = 1;
                e->format = EXIF_FORMAT_UNDEFINED;
                e->size = exif_format_get_size (e->format) * e->components;
-               e->data = exif_entry_malloc (e, e->size);
+               e->data = exif_entry_alloc (e, e->size);
                if (!e->data) break;
                e->data[0] = 0x01;
                break;
@@ -1085,7 +1079,7 @@ exif_entry_initialize (ExifEntry *e, ExifTag tag)
                e->components = 1;
                e->format = EXIF_FORMAT_UNDEFINED;
                e->size = exif_format_get_size (e->format) * e->components;
-               e->data = exif_entry_malloc (e, e->size);
+               e->data = exif_entry_alloc (e, e->size);
                if (!e->data) break;
                e->data[0] = 0x03;
                break;
@@ -1095,7 +1089,7 @@ exif_entry_initialize (ExifEntry *e, ExifTag tag)
                 e->components = 4;
                 e->format = EXIF_FORMAT_UNDEFINED;
                 e->size = exif_format_get_size (e->format) * e->components;
-                e->data = exif_entry_malloc (e, e->size);
+                e->data = exif_entry_alloc (e, e->size);
                if (!e->data) break;
                 memcpy (e->data, "0100", 4);
                 break;
@@ -1105,7 +1099,7 @@ exif_entry_initialize (ExifEntry *e, ExifTag tag)
                 e->components = 4;
                 e->format = EXIF_FORMAT_UNDEFINED;
                 e->size = exif_format_get_size (e->format) * e->components;
-                e->data = exif_entry_malloc (e, e->size);
+                e->data = exif_entry_alloc (e, e->size);
                if (!e->data) break;
                 memcpy (e->data, "0210", 4);
                 break;