s/malloc/xmalloc/ s/calloc/xcalloc/ s/realloc/realloc/
authorgraham.gower <graham.gower@e8e0d7a0-c8d9-11dd-a880-a1081c7ac358>
Thu, 5 Nov 2009 04:20:09 +0000 (04:20 +0000)
committergraham.gower <graham.gower@e8e0d7a0-c8d9-11dd-a880-a1081c7ac358>
Thu, 5 Nov 2009 04:20:09 +0000 (04:20 +0000)
And redundant error checking removed from the places where allocation failures
were actually checked.

git-svn-id: http://opkg.googlecode.com/svn/trunk@259 e8e0d7a0-c8d9-11dd-a880-a1081c7ac358

21 files changed:
libopkg/active_list.c
libopkg/file_util.c
libopkg/hash_table.c
libopkg/nv_pair_list.c
libopkg/opkg.c
libopkg/opkg_cmd.c
libopkg/opkg_conf.c
libopkg/opkg_install.c
libopkg/opkg_remove.c
libopkg/opkg_utils.c
libopkg/pkg.c
libopkg/pkg_depends.c
libopkg/pkg_dest_list.c
libopkg/pkg_hash.c
libopkg/pkg_parse.c
libopkg/pkg_src_list.c
libopkg/pkg_vec.c
libopkg/sprintf_alloc.c
libopkg/str_list.c
libopkg/void_list.c
libopkg/xregex.c

index 1d38d8d6bc7c09e37c64dbbd02af2452f5ea2a42..6b177c6fe703fca54865932b5246355639297763 100644 (file)
@@ -21,6 +21,7 @@
 #include <string.h>
 #include <stdlib.h>
 
 #include <string.h>
 #include <stdlib.h>
 
+#include "libbb/libbb.h"
 
 void active_list_init(struct active_list *ptr) {
     INIT_LIST_HEAD(&ptr->node);
 
 void active_list_init(struct active_list *ptr) {
     INIT_LIST_HEAD(&ptr->node);
@@ -119,7 +120,7 @@ void active_list_add(struct active_list *head, struct active_list *node) {
 }
 
 struct active_list * active_list_head_new() {
 }
 
 struct active_list * active_list_head_new() {
-    struct active_list * head = calloc(1, sizeof(struct active_list));
+    struct active_list * head = xcalloc(1, sizeof(struct active_list));
     active_list_init(head);
     return head;
 }
     active_list_init(head);
     return head;
 }
index b867df76a2b0a23dc29a51c40a42f5b0f7ccec9a..902b8c935477d35e7da8a26434f2d087cfa4eae4 100644 (file)
@@ -75,11 +75,7 @@ char *file_read_line_alloc(FILE *file)
        buf_len = strlen(buf);
        if (line) {
            line_size += buf_len;
        buf_len = strlen(buf);
        if (line) {
            line_size += buf_len;
-           line = realloc(line, line_size);
-           if (line == NULL) {
-               fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
-               break;
-           }
+           line = xrealloc(line, line_size);
            strcat(line, buf);
        } else {
            line_size = buf_len + 1;
            strcat(line, buf);
        } else {
            line_size = buf_len + 1;
@@ -147,11 +143,7 @@ char *file_md5sum_alloc(const char *file_name)
     char *md5sum_hex;
     unsigned char md5sum_bin[md5sum_bin_len];
 
     char *md5sum_hex;
     unsigned char md5sum_bin[md5sum_bin_len];
 
-    md5sum_hex = calloc(1, md5sum_hex_len + 1);
-    if (md5sum_hex == NULL) {
-       fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
-       return NULL;
-    }
+    md5sum_hex = xcalloc(1, md5sum_hex_len + 1);
 
     file = fopen(file_name, "r");
     if (file == NULL) {
 
     file = fopen(file_name, "r");
     if (file == NULL) {
@@ -200,11 +192,7 @@ char *file_sha256sum_alloc(const char *file_name)
     char *sha256sum_hex;
     unsigned char sha256sum_bin[sha256sum_bin_len];
 
     char *sha256sum_hex;
     unsigned char sha256sum_bin[sha256sum_bin_len];
 
-    sha256sum_hex = calloc(1, sha256sum_hex_len + 1);
-    if (sha256sum_hex == NULL) {
-       fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
-       return NULL;
-    }
+    sha256sum_hex = xcalloc(1, sha256sum_hex_len + 1);
 
     file = fopen(file_name, "r");
     if (file == NULL) {
 
     file = fopen(file_name, "r");
     if (file == NULL) {
index 6de90856d8694ccf06aec96890f4f62e5d88d4b7..df6ff4f024b313ba48128938771f4435ecf852ae 100644 (file)
@@ -69,11 +69,8 @@ int hash_table_init(const char *name, hash_table_t *hash, int len)
     --picker;
 
     hash->n_entries = *picker;
     --picker;
 
     hash->n_entries = *picker;
-    hash->entries = (hash_entry_t *)calloc(hash->n_entries, sizeof(hash_entry_t));
-    if (hash->entries == NULL) {
-       fprintf(stderr, "%s: Out of memory.\n", __FUNCTION__);
-       return ENOMEM;
-    }
+    hash->entries = xcalloc(hash->n_entries, sizeof(hash_entry_t));
+
     return 0;
 }
 
     return 0;
 }
 
@@ -147,10 +144,7 @@ int hash_table_insert(hash_table_t *hash, const char *key, void *value)
                         return 0;
                     }
                }
                         return 0;
                     }
                }
-              hash_entry->next = (hash_entry_t *)calloc(1, sizeof(hash_entry_t));
-              if (!hash_entry->next) {
-                   return -ENOMEM;
-              }
+              hash_entry->next = xcalloc(1, sizeof(hash_entry_t));
               hash_entry = hash_entry->next;
               hash_entry->next = NULL;
          }
               hash_entry = hash_entry->next;
               hash_entry->next = NULL;
          }
index e98d7188a847e0aeb0085edbb2a5c6935168d21f..5b6d4ff5b1c412de9455c6448850f2438757398c 100644 (file)
@@ -20,7 +20,7 @@
 #include "nv_pair.h"
 #include "void_list.h"
 #include "nv_pair_list.h"
 #include "nv_pair.h"
 #include "void_list.h"
 #include "nv_pair_list.h"
-
+#include "libbb/libbb.h"
 
 int nv_pair_list_init(nv_pair_list_t *list)
 {
 
 int nv_pair_list_init(nv_pair_list_t *list)
 {
@@ -51,12 +51,7 @@ nv_pair_t *nv_pair_list_append(nv_pair_list_t *list, const char *name, const cha
     int err;
 
     /* freed in nv_pair_list_deinit */
     int err;
 
     /* freed in nv_pair_list_deinit */
-    nv_pair_t *nv_pair = calloc(1, sizeof(nv_pair_t));
-
-    if (nv_pair == NULL) {
-       fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
-       return NULL;
-    }
+    nv_pair_t *nv_pair = xcalloc(1, sizeof(nv_pair_t));
     nv_pair_init(nv_pair, name, value);
 
     err = void_list_append((void_list_t *) list, nv_pair);
     nv_pair_init(nv_pair, name, value);
 
     err = void_list_append((void_list_t *) list, nv_pair);
index 437544007edbb144355a1d97cca38fbef8fa8d24..d7948e9ab537722e479905153fde74fe8366a88d 100644 (file)
@@ -162,7 +162,7 @@ opkg_package_new ()
 
   opkg_package_t *p;
 
 
   opkg_package_t *p;
 
-  p = calloc (1, sizeof (opkg_package_t));
+  p = xcalloc(1, sizeof (opkg_package_t));
 
   return p;
 }
 
   return p;
 }
@@ -187,9 +187,9 @@ opkg_new ()
   opkg_t *opkg;
   int err;
 
   opkg_t *opkg;
   int err;
 
-  opkg = calloc (1, sizeof (opkg_t));
+  opkg = xcalloc(1, sizeof (opkg_t));
 
 
-  opkg->args = calloc (1, sizeof (args_t));
+  opkg->args = xcalloc(1, sizeof (args_t));
   err = args_init (opkg->args);
   if (err)
   {
   err = args_init (opkg->args);
   if (err)
   {
@@ -198,7 +198,7 @@ opkg_new ()
     return NULL;
   }
 
     return NULL;
   }
 
-  opkg->conf = calloc (1, sizeof (opkg_conf_t));
+  opkg->conf = xcalloc(1, sizeof (opkg_conf_t));
   err = opkg_conf_init (opkg->conf, opkg->args);
   if (err)
   {
   err = opkg_conf_init (opkg->conf, opkg->args);
   if (err)
   {
index 9c1612b6f7b04fd095a2b306cf2e03bbdf86a0ac..807777e56870f0ef7542bc56983d737f51ec5b8d 100644 (file)
@@ -306,7 +306,7 @@ static opkg_intercept_t opkg_prep_intercepts(opkg_conf_t *conf)
     char *newpath;
     int gen;
 
     char *newpath;
     int gen;
 
-    ctx = calloc (1, sizeof (*ctx));
+    ctx = xcalloc(1, sizeof (*ctx));
     ctx->oldpath = xstrdup(getenv("PATH"));
 
     sprintf_alloc (&newpath, "%s/opkg/intercept:%s", DATADIR, ctx->oldpath);
     ctx->oldpath = xstrdup(getenv("PATH"));
 
     sprintf_alloc (&newpath, "%s/opkg/intercept:%s", DATADIR, ctx->oldpath);
@@ -877,7 +877,7 @@ static int opkg_remove_cmd(opkg_conf_t *conf, int argc, char **argv)
         available = pkg_vec_alloc();
         pkg_hash_fetch_all_installed(&conf->pkg_hash, available);
         for (i=0; i < argc; i++) {
         available = pkg_vec_alloc();
         pkg_hash_fetch_all_installed(&conf->pkg_hash, available);
         for (i=0; i < argc; i++) {
-           pkg_name = calloc(1, strlen(argv[i])+2);
+           pkg_name = xcalloc(1, strlen(argv[i])+2);
            strcpy(pkg_name,argv[i]);
            for (a=0; a < available->len; a++) {
                pkg = available->pkgs[a];
            strcpy(pkg_name,argv[i]);
            for (a=0; a < available->len; a++) {
                pkg = available->pkgs[a];
index a273c3076897563837dc534affb0745f136e70bc..cfbdc5bba8e883aed62a245d8f62a3e37cad42bf 100644 (file)
@@ -94,12 +94,7 @@ int opkg_init_options_array(const opkg_conf_t *conf, opkg_option_t **options)
          { NULL }
      };
 
          { NULL }
      };
 
-     *options = (opkg_option_t *)calloc(1, sizeof(tmp));
-     if ( options == NULL ){
-        fprintf(stderr,"%s: Unable to allocate memory\n",__FUNCTION__);
-        return -1;
-     }
-
+     *options = xcalloc(1, sizeof(tmp));
      memcpy(*options, tmp, sizeof(tmp));
      return 0;
 };
      memcpy(*options, tmp, sizeof(tmp));
      return 0;
 };
@@ -186,7 +181,7 @@ int opkg_conf_init(opkg_conf_t *conf, const args_t *args)
      pkg_hash_init("pkg-hash", &conf->pkg_hash, OPKG_CONF_DEFAULT_HASH_LEN);
      hash_table_init("file-hash", &conf->file_hash, OPKG_CONF_DEFAULT_HASH_LEN);
      hash_table_init("obs-file-hash", &conf->obs_file_hash, OPKG_CONF_DEFAULT_HASH_LEN);
      pkg_hash_init("pkg-hash", &conf->pkg_hash, OPKG_CONF_DEFAULT_HASH_LEN);
      hash_table_init("file-hash", &conf->file_hash, OPKG_CONF_DEFAULT_HASH_LEN);
      hash_table_init("obs-file-hash", &conf->obs_file_hash, OPKG_CONF_DEFAULT_HASH_LEN);
-     lists_dir=(char *)malloc(1);
+     lists_dir=xmalloc(1);
      lists_dir[0]='\0';
      if (args->conf_file) {
          struct stat stat_buf;
      lists_dir[0]='\0';
      if (args->conf_file) {
          struct stat stat_buf;
@@ -200,7 +195,7 @@ int opkg_conf_init(opkg_conf_t *conf, const args_t *args)
      }
 
      if (strlen(lists_dir)<=1 ){
      }
 
      if (strlen(lists_dir)<=1 ){
-        lists_dir = realloc(lists_dir,strlen(OPKG_CONF_LISTS_DIR)+2);
+        lists_dir = xrealloc(lists_dir,strlen(OPKG_CONF_LISTS_DIR)+2);
         sprintf (lists_dir,"%s",OPKG_CONF_LISTS_DIR);
      }
 
         sprintf (lists_dir,"%s",OPKG_CONF_LISTS_DIR);
      }
 
@@ -211,7 +206,7 @@ int opkg_conf_init(opkg_conf_t *conf, const args_t *args)
             lists_dir = tmp;
      }
 
             lists_dir = tmp;
      }
 
-     pending_dir = calloc(1, strlen(lists_dir)+strlen("/pending")+5);
+     pending_dir = xcalloc(1, strlen(lists_dir)+strlen("/pending")+5);
      snprintf(pending_dir,strlen(lists_dir)+strlen("/pending") ,"%s%s",lists_dir,"/pending");
 
      conf->lists_dir = xstrdup(lists_dir);
      snprintf(pending_dir,strlen(lists_dir)+strlen("/pending") ,"%s%s",lists_dir,"/pending");
 
      conf->lists_dir = xstrdup(lists_dir);
@@ -619,12 +614,7 @@ static int opkg_conf_parse_file(opkg_conf_t *conf, const char *filename,
          } else if (strcmp(type, "dest") == 0) {
               nv_pair_list_append(tmp_dest_nv_pair_list, name, value);
          } else if (strcmp(type, "lists_dir") == 0) {
          } else if (strcmp(type, "dest") == 0) {
               nv_pair_list_append(tmp_dest_nv_pair_list, name, value);
          } else if (strcmp(type, "lists_dir") == 0) {
-              *lists_dir = realloc(*lists_dir,strlen(value)+1);
-               if (*lists_dir == NULL) {
-                   opkg_message(conf, OPKG_ERROR, "ERROR: Not enough memory\n");
-                   free(options);
-                   return EINVAL;
-               }
+              *lists_dir = xrealloc(*lists_dir,strlen(value)+1);
                sprintf (*lists_dir,"%s",value);
          } else if (strcmp(type, "arch") == 0) {
               opkg_message(conf, OPKG_INFO, "supported arch %s priority (%s)\n", name, value);
                sprintf (*lists_dir,"%s",value);
          } else if (strcmp(type, "arch") == 0) {
               opkg_message(conf, OPKG_INFO, "supported arch %s priority (%s)\n", name, value);
index 2d5bb4e4692b40b44c468bc664f1ca39ca677c51..61563d6756cfa175b9c61e5d499454a2d2c3591f 100644 (file)
@@ -600,14 +600,14 @@ static int pkg_remove_orphan_dependent(opkg_conf_t *conf, pkg_t *pkg, pkg_t *old
         if (found)
             continue;
         d_str = old_pkg->depends_str[i];
         if (found)
             continue;
         d_str = old_pkg->depends_str[i];
-        buf = calloc (1, strlen (d_str) + 1);
+        buf = xcalloc(1, strlen (d_str) + 1);
         j=0;
         while (d_str[j] != '\0' && d_str[j] != ' ') {
             buf[j]=d_str[j];
             ++j;
         }
         buf[j]='\0';
         j=0;
         while (d_str[j] != '\0' && d_str[j] != ' ') {
             buf[j]=d_str[j];
             ++j;
         }
         buf[j]='\0';
-        buf = realloc (buf, strlen (buf) + 1);
+        buf = xrealloc (buf, strlen (buf) + 1);
         p = pkg_hash_fetch_installed_by_name (&conf->pkg_hash, buf);
         if (!p) {
             fprintf(stderr, "The pkg %s had been removed!!\n", buf);
         p = pkg_hash_fetch_installed_by_name (&conf->pkg_hash, buf);
         if (!p) {
             fprintf(stderr, "The pkg %s had been removed!!\n", buf);
index 1eda4f6a17fae395968710e25f9b07e204f629b8..ec7540b896cbd648c56a3e81ff2df3468ad97abd 100644 (file)
@@ -27,6 +27,7 @@
 #include "file_util.h"
 #include "sprintf_alloc.h"
 #include "str_util.h"
 #include "file_util.h"
 #include "sprintf_alloc.h"
 #include "str_util.h"
+#include "libbb/libbb.h"
 
 /*
  * Returns number of the number of packages depending on the packages provided by this package.
 
 /*
  * Returns number of the number of packages depending on the packages provided by this package.
@@ -54,12 +55,7 @@ int pkg_has_installed_dependents(opkg_conf_t *conf, abstract_pkg_t *parent_apkg,
      /* if caller requested the set of installed dependents */
      if (pdependents) {
          int p = 0;
      /* if caller requested the set of installed dependents */
      if (pdependents) {
          int p = 0;
-         abstract_pkg_t **dependents = (abstract_pkg_t **)calloc((n_installed_dependents+1), sizeof(abstract_pkg_t *));
-
-          if ( dependents == NULL ){
-              fprintf(stderr,"%s Unable to allocate memory. REPORT THIS BUG IN BUGZILLA PLEASE\n", __FUNCTION__);
-              return -1;  
-          }
+         abstract_pkg_t **dependents = xcalloc((n_installed_dependents+1), sizeof(abstract_pkg_t *));
 
          *pdependents = dependents;
          for (i = 0; i <= nprovides; i++) {
 
          *pdependents = dependents;
          for (i = 0; i <= nprovides; i++) {
@@ -181,12 +177,7 @@ static int remove_autoinstalled (opkg_conf_t *conf, pkg_t *pkg)
     int x = 0;
     pkg_t *p;
     d_str = pkg->depends_str[i];
     int x = 0;
     pkg_t *p;
     d_str = pkg->depends_str[i];
-    buffer = calloc (1, strlen (d_str) + 1);
-    if (!buffer)
-    {
-      fprintf(stderr,"%s Unable to allocate memory.\n", __FUNCTION__);
-      return -1;
-    }
+    buffer = xcalloc(1, strlen (d_str) + 1);
 
     while (d_str[x] != '\0' && d_str[x] != ' ')
     {
 
     while (d_str[x] != '\0' && d_str[x] != ' ')
     {
@@ -194,7 +185,7 @@ static int remove_autoinstalled (opkg_conf_t *conf, pkg_t *pkg)
       ++x;
     }
     buffer[x] = '\0';
       ++x;
     }
     buffer[x] = '\0';
-    buffer = realloc (buffer, strlen (buffer) + 1);
+    buffer = xrealloc (buffer, strlen (buffer) + 1);
     p = pkg_hash_fetch_installed_by_name (&conf->pkg_hash, buffer);
 
     /* if the package is not installed, this could have been a circular
     p = pkg_hash_fetch_installed_by_name (&conf->pkg_hash, buffer);
 
     /* if the package is not installed, this could have been a circular
index ccc3496666333caa414d96527c851e0dbfef8fb3..20af4d5a73bf4776dfadadf8051b669d487727a7 100644 (file)
@@ -70,20 +70,20 @@ char **read_raw_pkgs_from_stream(FILE *fp)
      int count = 0;
      size_t size = 512;
      
      int count = 0;
      size_t size = 512;
      
-     buf = calloc (1, size);
+     buf = xcalloc(1, size);
 
      while (fgets(buf, size, fp)) {
          while (strlen (buf) == (size - 1)
                 && buf[size-2] != '\n') {
               size_t o = size - 1;
               size *= 2;
 
      while (fgets(buf, size, fp)) {
          while (strlen (buf) == (size - 1)
                 && buf[size-2] != '\n') {
               size_t o = size - 1;
               size *= 2;
-              buf = realloc (buf, size);
+              buf = xrealloc (buf, size);
               if (fgets (buf + o, size - o, fp) == NULL)
                    break;
          }
          
          if(!(count % 50))
               if (fgets (buf + o, size - o, fp) == NULL)
                    break;
          }
          
          if(!(count % 50))
-              raw = realloc(raw, (count + 50) * sizeof(char *));
+              raw = xrealloc(raw, (count + 50) * sizeof(char *));
        
          if((scout = strchr(buf, '\n')))
               *scout = '\0';
        
          if((scout = strchr(buf, '\n')))
               *scout = '\0';
@@ -91,7 +91,7 @@ char **read_raw_pkgs_from_stream(FILE *fp)
          raw[count++] = xstrdup(buf);
      }
     
          raw[count++] = xstrdup(buf);
      }
     
-     raw = realloc(raw, (count + 1) * sizeof(char *));
+     raw = xrealloc(raw, (count + 1) * sizeof(char *));
      raw[count] = NULL;
 
      free (buf);
      raw[count] = NULL;
 
      free (buf);
@@ -105,11 +105,7 @@ char *trim_alloc(char *line)
      char *new; 
      char *dest, *src, *end;
     
      char *new; 
      char *dest, *src, *end;
     
-     new = calloc(1, strlen(line) + 1);
-     if ( new == NULL ){
-        fprintf(stderr,"%s: Unable to allocate memory\n",__FUNCTION__);
-        return NULL;
-     }
+     new = xcalloc(1, strlen(line) + 1);
      dest = new, src = line, end = line + (strlen(line) - 1);
 
      /* remove it from the front */    
      dest = new, src = line, end = line + (strlen(line) - 1);
 
      /* remove it from the front */    
@@ -157,13 +153,7 @@ void push_error_list(char * msg)
 {
        struct errlist *e;
 
 {
        struct errlist *e;
 
-       e = calloc(1,  sizeof(struct errlist));
-       if (e == NULL) {
-               fprintf(stderr, "%s: calloc: %s\n",
-                               __FUNCTION__, strerror(errno));
-               return;
-       }
-
+       e = xcalloc(1,  sizeof(struct errlist));
        e->errmsg = xstrdup(msg);
        e->next = NULL;
 
        e->errmsg = xstrdup(msg);
        e->next = NULL;
 
index 33d0d68f7428d2f482f2740326ec7041c8352be3..48169ea7ad6c22100bd0e15ab85a7e6a460eb317 100644 (file)
@@ -79,7 +79,7 @@ pkg_t *pkg_new(void)
 {
      pkg_t *pkg;
 
 {
      pkg_t *pkg;
 
-     pkg = calloc(1, sizeof(pkg_t));
+     pkg = xcalloc(1, sizeof(pkg_t));
      if (pkg == NULL) {
          fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
          return NULL;
      if (pkg == NULL) {
          fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
          return NULL;
@@ -450,7 +450,7 @@ abstract_pkg_t *abstract_pkg_new(void)
 {
      abstract_pkg_t * ab_pkg;
 
 {
      abstract_pkg_t * ab_pkg;
 
-     ab_pkg = calloc(1, sizeof(abstract_pkg_t));
+     ab_pkg = xcalloc(1, sizeof(abstract_pkg_t));
 
      if (ab_pkg == NULL) {
          fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
 
      if (ab_pkg == NULL) {
          fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
@@ -992,10 +992,6 @@ str_list_t *pkg_get_installed_files(pkg_t *pkg)
      }
 
      pkg->installed_files = str_list_alloc();
      }
 
      pkg->installed_files = str_list_alloc();
-     if (pkg->installed_files == NULL) {
-         fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
-         return NULL;
-     }
 
      /* For uninstalled packages, get the file list directly from the package.
        For installed packages, look at the package.list file in the database.
 
      /* For uninstalled packages, get the file list directly from the package.
        For installed packages, look at the package.list file in the database.
@@ -1262,11 +1258,7 @@ char *pkg_state_flag_to_str(pkg_state_flag_t sf)
                    len += strlen(pkg_state_flag_map[i].str) + 1;
               }
          }
                    len += strlen(pkg_state_flag_map[i].str) + 1;
               }
          }
-         str = malloc(len);
-          if ( str == NULL ) {
-             fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
-              return NULL;
-          }
+         str = xmalloc(len);
          str[0] = 0;
          for (i=0; i < ARRAY_SIZE(pkg_state_flag_map); i++) {
               if (sf & pkg_state_flag_map[i].value) {
          str[0] = 0;
          for (i=0; i < ARRAY_SIZE(pkg_state_flag_map); i++) {
               if (sf & pkg_state_flag_map[i].value) {
index 6ce9fdd3c8e2aeca37605ee62e46f9110a4e0d80..3210e9df5cffd81b3f1aee15009bad854a39edd1 100644 (file)
@@ -573,24 +573,20 @@ static char ** merge_unresolved(char ** oldstuff, char ** newstuff)
 
     if(!newstuff)
        return oldstuff;
 
     if(!newstuff)
        return oldstuff;
-    
+
     while(oldstuff && oldstuff[oldlen]) oldlen++;
     while(newstuff && newstuff[newlen]) newlen++;
     while(oldstuff && oldstuff[oldlen]) oldlen++;
     while(newstuff && newstuff[newlen]) newlen++;
-    
-    result = (char **)realloc(oldstuff, sizeof(char *) * (oldlen + newlen + 1));
-    if (result == NULL) {
-        fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
-        return NULL;
-    }
-    
+
+    result = xrealloc(oldstuff, sizeof(char *) * (oldlen + newlen + 1));
+
     for(i = oldlen, j = 0; i < (oldlen + newlen); i++, j++)
        *(result + i) = *(newstuff + j);
     for(i = oldlen, j = 0; i < (oldlen + newlen); i++, j++)
        *(result + i) = *(newstuff + j);
-    
+
     *(result + i) = NULL;
 
     return result;
 }
     *(result + i) = NULL;
 
     return result;
 }
-    
+
 /* 
  * a kinda kludgy way to back out depends str from two different arrays (reg'l'r 'n pre)
  * this is null terminated, no count is carried around 
 /* 
  * a kinda kludgy way to back out depends str from two different arrays (reg'l'r 'n pre)
  * this is null terminated, no count is carried around 
@@ -605,11 +601,7 @@ char ** add_unresolved_dep(pkg_t * pkg, char ** the_lost, int ref_ndx)
     while(the_lost && the_lost[count]) count++;
 
     count++;  /* need one to hold the null */
     while(the_lost && the_lost[count]) count++;
 
     count++;  /* need one to hold the null */
-    resized = (char **)realloc(the_lost, sizeof(char *) * (count + 1));
-    if (resized == NULL) {
-       fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
-       return NULL;
-    }
+    resized = xrealloc(the_lost, sizeof(char *) * (count + 1));
     resized[count - 1] = xstrdup(depend_str);
     resized[count] = NULL;
     
     resized[count - 1] = xstrdup(depend_str);
     resized[count] = NULL;
     
@@ -654,11 +646,7 @@ int buildProvides(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg)
     if (pkg->provides)
       return 0;
 
     if (pkg->provides)
       return 0;
 
-    pkg->provides = (abstract_pkg_t **)calloc((pkg->provides_count + 1), sizeof(abstract_pkg_t *));
-    if (pkg->provides == NULL) {
-       fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
-       return -1 ;
-    }
+    pkg->provides = xcalloc((pkg->provides_count + 1), sizeof(abstract_pkg_t *));
     pkg->provides[0] = ab_pkg;
 
     // if (strcmp(ab_pkg->name, pkg->name))
     pkg->provides[0] = ab_pkg;
 
     // if (strcmp(ab_pkg->name, pkg->name))
@@ -684,11 +672,7 @@ int buildConflicts(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg)
     if (!pkg->conflicts_count)
        return 0;
 
     if (!pkg->conflicts_count)
        return 0;
 
-    conflicts = pkg->conflicts = calloc(pkg->conflicts_count, sizeof(compound_depend_t));
-    if (conflicts == NULL) {
-       fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
-       return  -1;
-    }
+    conflicts = pkg->conflicts = xcalloc(pkg->conflicts_count, sizeof(compound_depend_t));
     for (i = 0; i < pkg->conflicts_count; i++) {
         conflicts->type = CONFLICTS;
         parseDepends(conflicts, hash,
     for (i = 0; i < pkg->conflicts_count; i++) {
         conflicts->type = CONFLICTS;
         parseDepends(conflicts, hash,
@@ -705,11 +689,7 @@ int buildReplaces(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg)
      if (!pkg->replaces_count)
          return 0;
 
      if (!pkg->replaces_count)
          return 0;
 
-     pkg->replaces = (abstract_pkg_t **)calloc(pkg->replaces_count, sizeof(abstract_pkg_t *));
-     if (pkg->replaces == NULL) {
-        fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
-        return  -1;
-     }
+     pkg->replaces = xcalloc(pkg->replaces_count, sizeof(abstract_pkg_t *));
 
      for(i = 0; i < pkg->replaces_count; i++){
          abstract_pkg_t *old_abpkg = ensure_abstract_pkg_by_name(hash, pkg->replaces_str[i]);
 
      for(i = 0; i < pkg->replaces_count; i++){
          abstract_pkg_t *old_abpkg = ensure_abstract_pkg_by_name(hash, pkg->replaces_str[i]);
@@ -719,9 +699,6 @@ int buildReplaces(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg)
          j = 0;
          if (!old_abpkg->replaced_by)
               old_abpkg->replaced_by = abstract_pkg_vec_alloc();
          j = 0;
          if (!old_abpkg->replaced_by)
               old_abpkg->replaced_by = abstract_pkg_vec_alloc();
-               if ( old_abpkg->replaced_by == NULL ){
-                  return -1;
-               }
          /* if a package pkg both replaces and conflicts old_abpkg,
           * then add it to the replaced_by vector so that old_abpkg
           * will be upgraded to ab_pkg automatically */
          /* if a package pkg both replaces and conflicts old_abpkg,
           * then add it to the replaced_by vector so that old_abpkg
           * will be upgraded to ab_pkg automatically */
@@ -743,12 +720,7 @@ int buildDepends(hash_table_t * hash, pkg_t * pkg)
      if (0 && pkg->pre_depends_count)
          fprintf(stderr, "pkg=%s pre_depends_count=%d depends_count=%d\n", 
                  pkg->name, pkg->pre_depends_count, pkg->depends_count);
      if (0 && pkg->pre_depends_count)
          fprintf(stderr, "pkg=%s pre_depends_count=%d depends_count=%d\n", 
                  pkg->name, pkg->pre_depends_count, pkg->depends_count);
-     depends = pkg->depends = calloc(count, sizeof(compound_depend_t));
-     if (depends == NULL) {
-        fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
-        return  -1;
-     }
-     
+     depends = pkg->depends = xcalloc(count, sizeof(compound_depend_t));
 
      for(i = 0; i < pkg->pre_depends_count; i++){
          parseDepends(depends, hash, pkg->pre_depends_str[i]);
 
      for(i = 0; i < pkg->pre_depends_count; i++){
          parseDepends(depends, hash, pkg->pre_depends_str[i]);
@@ -856,7 +828,7 @@ void buildDependedUponBy(pkg_t * pkg, abstract_pkg_t * ab_pkg)
          for (j = 0; j < depends->possibility_count; j++){
               ab_depend = depends->possibilities[j]->pkg;
               if(!ab_depend->depended_upon_by)
          for (j = 0; j < depends->possibility_count; j++){
               ab_depend = depends->possibilities[j]->pkg;
               if(!ab_depend->depended_upon_by)
-                   ab_depend->depended_upon_by = (abstract_pkg_t **)calloc(1, sizeof(abstract_pkg_t *));
+                   ab_depend->depended_upon_by = xcalloc(1, sizeof(abstract_pkg_t *));
 
               temp = ab_depend->depended_upon_by;
               othercount = 1;
 
               temp = ab_depend->depended_upon_by;
               othercount = 1;
@@ -866,7 +838,7 @@ void buildDependedUponBy(pkg_t * pkg, abstract_pkg_t * ab_pkg)
               }
               *temp = ab_pkg;
 
               }
               *temp = ab_pkg;
 
-              ab_depend->depended_upon_by = (abstract_pkg_t **)realloc(ab_depend->depended_upon_by, 
+              ab_depend->depended_upon_by = xrealloc(ab_depend->depended_upon_by, 
                                                                        (othercount + 1) * sizeof(abstract_pkg_t *));
               /* the array may have moved */
               temp = ab_depend->depended_upon_by + othercount;
                                                                        (othercount + 1) * sizeof(abstract_pkg_t *));
               /* the array may have moved */
               temp = ab_depend->depended_upon_by + othercount;
@@ -878,11 +850,7 @@ void buildDependedUponBy(pkg_t * pkg, abstract_pkg_t * ab_pkg)
 
 static depend_t * depend_init(void)
 {
 
 static depend_t * depend_init(void)
 {
-    depend_t * d = (depend_t *)calloc(1, sizeof(depend_t));    
-    if ( d==NULL ){
-        fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
-        return NULL; 
-     }
+    depend_t * d = xcalloc(1, sizeof(depend_t));    
     d->constraint = NONE;
     d->version = NULL;
     d->pkg = NULL;
     d->constraint = NONE;
     d->version = NULL;
     d->pkg = NULL;
@@ -913,16 +881,12 @@ static int parseDepends(compound_depend_t *compound_depend,
      compound_depend->type = DEPEND;
 
      compound_depend->possibility_count = num_of_ors + 1;
      compound_depend->type = DEPEND;
 
      compound_depend->possibility_count = num_of_ors + 1;
-     possibilities = (depend_t **)calloc((num_of_ors + 1), sizeof(depend_t *) );
-     if (!possibilities)
-         return -ENOMEM;
+     possibilities = xcalloc((num_of_ors + 1), sizeof(depend_t *) );
      compound_depend->possibilities = possibilities;
 
      src = depend_str;
      for(i = 0; i < num_of_ors + 1; i++){
          possibilities[i] = depend_init();
      compound_depend->possibilities = possibilities;
 
      src = depend_str;
      for(i = 0; i < num_of_ors + 1; i++){
          possibilities[i] = depend_init();
-          if (!possibilities[i])
-              return -ENOMEM;
          /* gobble up just the name first */
          dest = buffer;
          while(*src &&
          /* gobble up just the name first */
          dest = buffer;
          while(*src &&
index 2c03e73975244149a00c376c8adbe2b028ecc268..f8a7c52e61dc6fbc40a376cbd57f4d6d03dd59ae 100644 (file)
@@ -20,6 +20,7 @@
 #include "pkg_dest.h"
 #include "void_list.h"
 #include "pkg_dest_list.h"
 #include "pkg_dest.h"
 #include "void_list.h"
 #include "pkg_dest_list.h"
+#include "libbb/libbb.h"
 
 int pkg_dest_list_elt_init(pkg_dest_list_elt_t *elt, pkg_dest_t *data)
 {
 
 int pkg_dest_list_elt_init(pkg_dest_list_elt_t *elt, pkg_dest_t *data)
 {
@@ -58,12 +59,8 @@ pkg_dest_t *pkg_dest_list_append(pkg_dest_list_t *list, const char *name,
     int err;
     pkg_dest_t *pkg_dest;
 
     int err;
     pkg_dest_t *pkg_dest;
 
-    /* freed in plg_dest_list_deinit */
-    pkg_dest = calloc(1, sizeof(pkg_dest_t));
-    if (pkg_dest == NULL) {
-       fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
-       return NULL;
-    }
+    /* freed in pkg_dest_list_deinit */
+    pkg_dest = xcalloc(1, sizeof(pkg_dest_t));
 
     pkg_dest_init(pkg_dest, name, root_dir,lists_dir);
     err = void_list_append((void_list_t *) list, pkg_dest);
 
     pkg_dest_init(pkg_dest, name, root_dir,lists_dir);
     err = void_list_append((void_list_t *) list, pkg_dest);
index 978ccb2cec8ebaadd7ae1d5ff862e4b799f6ba8d..e92a56f0de8e34db701472ec32f3079180eea4a4 100644 (file)
@@ -186,8 +186,7 @@ pkg_t *pkg_hash_fetch_best_installation_candidate(opkg_conf_t *conf, abstract_pk
      if (err)
        *err = 0;
 
      if (err)
        *err = 0;
 
-     if (matching_apkgs == NULL || providers == NULL || 
-         apkg == NULL || apkg->provided_by == NULL || (apkg->provided_by->len == 0))
+     if (apkg == NULL || apkg->provided_by == NULL || (apkg->provided_by->len == 0))
          return NULL;
 
      opkg_message(conf, OPKG_DEBUG, "best installation candidate for %s\n", apkg->name);
          return NULL;
 
      opkg_message(conf, OPKG_DEBUG, "best installation candidate for %s\n", apkg->name);
index 5389479a9c6c434be734db879d3b20c6e23fbf38..98d7a9b209b706af780c42cea8480f8352fca205 100644 (file)
@@ -62,7 +62,7 @@ char ** parseDependsString(char * raw, int * depends_count)
        return NULL;
     }
     while(raw && *raw){
        return NULL;
     }
     while(raw && *raw){
-       depends = (char **)realloc(depends, sizeof(char *) * (line_count + 1));
+       depends = xrealloc(depends, sizeof(char *) * (line_count + 1));
        
        while(isspace(*raw)) raw++;
 
        
        while(isspace(*raw)) raw++;
 
@@ -142,12 +142,8 @@ int parseVersion(pkg_t *pkg, char *raw)
 
   if (!pkg->version)
   {
 
   if (!pkg->version)
   {
-  pkg->version= calloc(1, strlen(raw)+1);
-  if ( pkg->version == NULL ) {
-     fprintf(stderr, "%s: out of memory \n", __FUNCTION__);
-     return ENOMEM;
-  }
-  strcpy(pkg->version, raw);
+    pkg->version= xcalloc(1, strlen(raw)+1);
+    strcpy(pkg->version, raw);
   }
 
   hyphen= strrchr(pkg->version,'-');
   }
 
   hyphen= strrchr(pkg->version,'-');
@@ -231,7 +227,7 @@ int pkg_parse_raw(pkg_t *pkg, char ***raw, pkg_src_t *src, pkg_dest_t *dest)
                pkg->priority = parseGenericFieldType("Priority", *lines);
            else if(isGenericFieldType("Provides", *lines)){
 /* Here we add the internal_use to align the off by one problem between provides_str and provides */
                pkg->priority = parseGenericFieldType("Priority", *lines);
            else if(isGenericFieldType("Provides", *lines)){
 /* Here we add the internal_use to align the off by one problem between provides_str and provides */
-               provide = (char * ) calloc(1, strlen(*lines)+ 35 ); /* Preparing the space for the new opkg_internal_use_only */
+               provide = xcalloc(1, strlen(*lines)+ 35 ); /* Preparing the space for the new opkg_internal_use_only */
                if ( alterProvidesLine(*lines,provide) ){
                    return EINVAL;
                }
                if ( alterProvidesLine(*lines,provide) ){
                    return EINVAL;
                }
@@ -353,7 +349,7 @@ int pkg_parse_raw(pkg_t *pkg, char ***raw, pkg_src_t *src, pkg_dest_t *dest)
        case ' ':
            if(reading_description) {
                /* we already know it's not blank, so the rest of description */      
        case ' ':
            if(reading_description) {
                /* we already know it's not blank, so the rest of description */      
-               pkg->description = realloc(pkg->description,
+               pkg->description = xrealloc(pkg->description,
                                           strlen(pkg->description)
                                           + 1 + strlen(*lines) + 1);
                strcat(pkg->description, "\n");
                                           strlen(pkg->description)
                                           + 1 + strlen(*lines) + 1);
                strcat(pkg->description, "\n");
@@ -378,7 +374,7 @@ out:;
     if ( pkg_false_provides==1)
     {
        pkg->provides_count = 1;
     if ( pkg_false_provides==1)
     {
        pkg->provides_count = 1;
-       pkg->provides_str = calloc (1, sizeof (char*));
+       pkg->provides_str = xcalloc(1, sizeof (char*));
        pkg->provides_str[0] = xstrdup("opkg_internal_use_only");
     }
 
        pkg->provides_str[0] = xstrdup("opkg_internal_use_only");
     }
 
index 9a2a90f45a8a0d9652b02f1d7f79cb58cf185208..cd7fce4d20a88d31e33ad0a7aeb37c27ee6c0c01 100644 (file)
@@ -19,6 +19,7 @@
 
 #include "pkg_src_list.h"
 #include "void_list.h"
 
 #include "pkg_src_list.h"
 #include "void_list.h"
+#include "libbb/libbb.h"
 
 int pkg_src_list_init(pkg_src_list_t *list)
 {
 
 int pkg_src_list_init(pkg_src_list_t *list)
 {
@@ -48,12 +49,7 @@ pkg_src_t *pkg_src_list_append(pkg_src_list_t *list,
     int err;
 
     /* freed in pkg_src_list_deinit */
     int err;
 
     /* freed in pkg_src_list_deinit */
-    pkg_src_t *pkg_src = calloc(1, sizeof(pkg_src_t));
-
-    if (pkg_src == NULL) {
-       fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
-       return NULL;
-    }
+    pkg_src_t *pkg_src = xcalloc(1, sizeof(pkg_src_t));
     pkg_src_init(pkg_src, name, base_url, extra_data, gzip);
 
     err = void_list_append((void_list_t *) list, pkg_src);
     pkg_src_init(pkg_src, name, base_url, extra_data, gzip);
 
     err = void_list_append((void_list_t *) list, pkg_src);
index fa2c2373d840b0dd79cb91793af84c3a6dba951b..9e4f26b812d09251d1b60cd8564caec72261a835 100644 (file)
 #include "xregex.h"
 #include "pkg.h"
 #include "opkg_message.h"
 #include "xregex.h"
 #include "pkg.h"
 #include "opkg_message.h"
+#include "libbb/libbb.h"
 
 pkg_vec_t * pkg_vec_alloc(void)
 {
 
 pkg_vec_t * pkg_vec_alloc(void)
 {
-    pkg_vec_t * vec = (pkg_vec_t *)calloc(1, sizeof(pkg_vec_t));
-    if (!vec) {
-      fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
-      return NULL;
-    }
+    pkg_vec_t * vec = xcalloc(1, sizeof(pkg_vec_t));
     vec->pkgs = NULL;
     vec->len = 0;
 
     vec->pkgs = NULL;
     vec->len = 0;
 
@@ -103,13 +100,7 @@ pkg_t *pkg_vec_insert_merge(pkg_vec_t *vec, pkg_t *pkg, int set_status,opkg_conf
 
 void pkg_vec_insert(pkg_vec_t *vec, const pkg_t *pkg)
 {
 
 void pkg_vec_insert(pkg_vec_t *vec, const pkg_t *pkg)
 {
-    pkg_t **tmp;
-    tmp = realloc(vec->pkgs, (vec->len + 1) * sizeof(pkg_t *));
-    if (tmp == NULL) {
-        fprintf(stderr, "%s: %s\n", __FUNCTION__, strerror(errno));
-       return;
-    }
-    vec->pkgs = tmp;
+    vec->pkgs = xrealloc(vec->pkgs, (vec->len + 1) * sizeof(pkg_t *));
     vec->pkgs[vec->len] = (pkg_t *)pkg;
     vec->len++;
 }
     vec->pkgs[vec->len] = (pkg_t *)pkg;
     vec->len++;
 }
@@ -159,11 +150,7 @@ int pkg_vec_mark_if_matches(pkg_vec_t *vec, const char *pattern)
 abstract_pkg_vec_t * abstract_pkg_vec_alloc(void)
 {
     abstract_pkg_vec_t * vec ; 
 abstract_pkg_vec_t * abstract_pkg_vec_alloc(void)
 {
     abstract_pkg_vec_t * vec ; 
-    vec = (abstract_pkg_vec_t *)calloc(1, sizeof(abstract_pkg_vec_t));
-    if (!vec) {
-      fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
-      return NULL;
-    }
+    vec = xcalloc(1, sizeof(abstract_pkg_vec_t));
     vec->pkgs = NULL;
     vec->len = 0;
 
     vec->pkgs = NULL;
     vec->len = 0;
 
@@ -183,13 +170,7 @@ void abstract_pkg_vec_free(abstract_pkg_vec_t *vec)
  */
 void abstract_pkg_vec_insert(abstract_pkg_vec_t *vec, abstract_pkg_t *pkg)
 {
  */
 void abstract_pkg_vec_insert(abstract_pkg_vec_t *vec, abstract_pkg_t *pkg)
 {
-    abstract_pkg_t **tmp;
-    tmp = realloc(vec->pkgs, (vec->len + 1) * sizeof(abstract_pkg_t *));
-    if (tmp == NULL) {
-        fprintf(stderr, "%s: %s\n", __FUNCTION__, strerror(errno));
-       return;
-    }
-    vec->pkgs = tmp;
+    vec->pkgs = xrealloc(vec->pkgs, (vec->len + 1) * sizeof(abstract_pkg_t *));
     vec->pkgs[vec->len] = pkg;
     vec->len++;
 }
     vec->pkgs[vec->len] = pkg;
     vec->len++;
 }
index 30ab033d257dabc8f378125f853f1ed4039da8ca..7989493aa4008425a03ca13c70814a29b66e9847 100644 (file)
 #include <stdarg.h>
 
 #include "sprintf_alloc.h"
 #include <stdarg.h>
 
 #include "sprintf_alloc.h"
+#include "libbb/libbb.h"
 
 int sprintf_alloc(char **str, const char *fmt, ...)
 {
     va_list ap;
 
 int sprintf_alloc(char **str, const char *fmt, ...)
 {
     va_list ap;
-    char *new_str;
     int n, size = 100;
 
     if (!str) {
     int n, size = 100;
 
     if (!str) {
@@ -44,13 +44,11 @@ int sprintf_alloc(char **str, const char *fmt, ...)
 
     /* ripped more or less straight out of PRINTF(3) */
 
 
     /* ripped more or less straight out of PRINTF(3) */
 
-    if ((new_str = calloc(1, size)) == NULL) 
-      return -1;
+    *str = xcalloc(1, size);
 
 
-    *str = new_str;
     while(1) {
       va_start(ap, fmt);
     while(1) {
       va_start(ap, fmt);
-      n = vsnprintf (new_str, size, fmt, ap);
+      n = vsnprintf (*str, size, fmt, ap);
       va_end(ap);
       /* If that worked, return the size. */
       if (n > -1 && n < size)
       va_end(ap);
       /* If that worked, return the size. */
       if (n > -1 && n < size)
@@ -60,13 +58,7 @@ int sprintf_alloc(char **str, const char *fmt, ...)
            size = n+1; /* precisely what is needed */
        else           /* glibc 2.0 */
            size *= 2;  /* twice the old size */
            size = n+1; /* precisely what is needed */
        else           /* glibc 2.0 */
            size *= 2;  /* twice the old size */
-       new_str = realloc(new_str, size);
-       if (new_str == NULL) {
-           free(new_str);
-           *str = NULL;
-           return -1;
-       }
-       *str = new_str;
+       *str = xrealloc(*str, size);
     }
 
     return -1; /* Just to be correct - it probably won't get here */
     }
 
     return -1; /* Just to be correct - it probably won't get here */
index be4296722cb0a3dc7cb621b8d6ace8b83275e188..a8e179d2d2893697af48c09cc97050cddac2c956 100644 (file)
@@ -33,9 +33,8 @@ void str_list_elt_deinit(str_list_elt_t *elt)
 
 str_list_t *str_list_alloc()
 {
 
 str_list_t *str_list_alloc()
 {
-     str_list_t *list = (str_list_t *)calloc(1, sizeof(str_list_t));
-     if (list)
-         str_list_init(list);
+     str_list_t *list = xcalloc(1, sizeof(str_list_t));
+     str_list_init(list);
      return list;
 }
 
      return list;
 }
 
index 1517228c16ce35a857a8a2d151fc3c0e3e0f17db..e36b4517688248af5a3f4000364dcecb58b76588 100644 (file)
@@ -19,6 +19,7 @@
 #include <errno.h>
 
 #include "void_list.h"
 #include <errno.h>
 
 #include "void_list.h"
+#include "libbb/libbb.h"
 
 int void_list_elt_init(void_list_elt_t *elt, void *data)
 {
 
 int void_list_elt_init(void_list_elt_t *elt, void *data)
 {
@@ -31,11 +32,7 @@ int void_list_elt_init(void_list_elt_t *elt, void *data)
 void_list_elt_t * void_list_elt_new (void *data) {
     void_list_elt_t *elt;
     /* freed in void_list_elt_deinit */
 void_list_elt_t * void_list_elt_new (void *data) {
     void_list_elt_t *elt;
     /* freed in void_list_elt_deinit */
-    elt = calloc(1, sizeof(void_list_elt_t));
-    if (elt == NULL) {
-       fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
-       return NULL;
-    }
+    elt = xcalloc(1, sizeof(void_list_elt_t));
     void_list_elt_init(elt, data);
     return elt;
 }
     void_list_elt_init(elt, data);
     return elt;
 }
index b0cd8b9cd9e8bcfef2072de0e01573e529c0db0c..ba22b7d598964c0efd9c95bc0d0606851b6d1713 100644 (file)
@@ -18,6 +18,7 @@
 #include "includes.h"
 
 #include "xregex.h"
 #include "includes.h"
 
 #include "xregex.h"
+#include "libbb/libbb.h"
 
 static void print_regcomp_err(const regex_t *preg, int err);
 
 
 static void print_regcomp_err(const regex_t *preg, int err);
 
@@ -39,10 +40,8 @@ static void print_regcomp_err(const regex_t *preg, int err)
     
     fprintf(stderr, "%s: Error compiling regex:", __FUNCTION__);
     size = regerror(err, preg, 0, 0);
     
     fprintf(stderr, "%s: Error compiling regex:", __FUNCTION__);
     size = regerror(err, preg, 0, 0);
-    error = calloc(1, size);
-    if (error) {
-       regerror(err, preg, error, size);
-       fprintf(stderr, "%s\n", error);
-    }
+    error = xcalloc(1, size);
+    regerror(err, preg, error, size);
+    fprintf(stderr, "%s\n", error);
     free(error);
 }
     free(error);
 }