[pango/harfbuzz-ng: 10/57] [HB] Use calloc instead of malloc where feasible



commit 86f7ff9415d71de495f6257edad2ba991692e042
Author: Behdad Esfahbod <behdad behdad org>
Date:   Sat Aug 1 19:05:44 2009 -0400

    [HB] Use calloc instead of malloc where feasible

 pango/opentype/hb-blob.c   |    8 +++++---
 pango/opentype/hb-buffer.c |    4 ++--
 2 files changed, 7 insertions(+), 5 deletions(-)
---
diff --git a/pango/opentype/hb-blob.c b/pango/opentype/hb-blob.c
index bcdf134..50bb973 100644
--- a/pango/opentype/hb-blob.c
+++ b/pango/opentype/hb-blob.c
@@ -30,20 +30,22 @@
 #include "hb-refcount-private.h"
 
 struct _hb_blob_t {
+  hb_reference_count_t ref_count;
+
   const char *data;
   unsigned int len;
   hb_memory_mode_t mode;
 
-  hb_reference_count_t ref_count;
   hb_destroy_func_t destroy;
   void *user_data;
 };
 static hb_blob_t _hb_blob_nil = {
+  HB_REFERENCE_COUNT_INVALID,
+
   NULL,
   0,
   HB_MEMORY_MODE_READONLY,
 
-  HB_REFERENCE_COUNT_INVALID,
   NULL,
   NULL
 };
@@ -67,7 +69,7 @@ hb_blob_create (const char        *data,
 {
   hb_blob_t *blob;
 
-  blob = malloc (sizeof (hb_blob_t));
+  blob = calloc (1, sizeof (hb_blob_t));
   if (!blob) {
     if (destroy)
       destroy (user_data);
diff --git a/pango/opentype/hb-buffer.c b/pango/opentype/hb-buffer.c
index 3c6fd7c..f596c09 100644
--- a/pango/opentype/hb-buffer.c
+++ b/pango/opentype/hb-buffer.c
@@ -59,7 +59,7 @@ hb_buffer_ensure_separate (hb_buffer_t *buffer, unsigned int size)
   if (buffer->out_string == buffer->in_string)
   {
     if (!buffer->alt_string)
-      buffer->alt_string = malloc (buffer->allocated * sizeof (buffer->alt_string[0]));
+      buffer->alt_string = calloc (buffer->allocated, sizeof (buffer->alt_string[0]));
 
     buffer->out_string = buffer->alt_string;
     memcpy (buffer->out_string, buffer->in_string, buffer->out_length * sizeof (buffer->out_string[0]));
@@ -73,7 +73,7 @@ hb_buffer_new (unsigned int allocation_size)
 {
   hb_buffer_t *buffer;
 
-  buffer = malloc (sizeof (hb_buffer_t));
+  buffer = calloc (1, sizeof (hb_buffer_t));
   if (HB_UNLIKELY (!buffer))
     return NULL;
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]