Don't cast returns from malloc()
[openafs.git] / src / export / cfgexport.c
index 41a1b71..762b7eb 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Copyright 2000, International Business Machines Corporation and others.
  * All Rights Reserved.
- * 
+ *
  * This software has been released under the terms of the IBM Public
  * License.  For details, see the LICENSE file in the top-level source
  * directory or online at http://www.openafs.org/dl/license10.html
@@ -13,8 +13,6 @@
 #include <afsconfig.h>
 #include <afs/param.h>
 
-RCSID
-    ("$Header$");
 
 #include <errno.h>
 #include <stdio.h>
@@ -42,8 +40,8 @@ char *xstrings;
 main(argc, argv)
      char **argv;
 {
-    register add, del, opts;
-    register c;
+    int add, del, opts;
+    int c;
     char *file;
     mid_t kmid;
     struct cfg_load cload;
@@ -53,8 +51,8 @@ main(argc, argv)
 
 #ifdef AFS_AIX32_ENV
     /*
-     * The following signal action for AIX is necessary so that in case of a 
-     * crash (i.e. core is generated) we can include the user's data section 
+     * The following signal action for AIX is necessary so that in case of a
+     * crash (i.e. core is generated) we can include the user's data section
      * in the core dump. Unfortunately, by default, only a partial core is
      * generated which, in many cases, isn't too useful.
      */
@@ -204,7 +202,7 @@ get_syms(conf, syms)
 
     if (syms == NULL)
       sys_error("syms is NULL");
-    fp = fopen(syms, "r"); 
+    fp = fopen(syms, "r");
     if (fp == NULL)
        sys_error(syms);
 
@@ -234,7 +232,7 @@ get_syms(conf, syms)
     if (debug)
        printf("nsyms = %d\n", nsyms);
 
-    x_symtab = (struct syment *)malloc(nsyms * SYMESZ);
+    x_symtab = malloc(nsyms * SYMESZ);
     if (!x_symtab)
        error("no memory for symbol table");
 
@@ -328,7 +326,7 @@ get_syms(conf, syms)
     /*
      * we will need no more than `nxsyms' symbols.
      */
-    k_symtab = (sym_t *) malloc(nxsyms * sizeof(sym_t));
+    k_symtab = malloc(nxsyms * sizeof(sym_t));
     if (!k_symtab)
        error("no memory for EXPORT symbol table");
 
@@ -377,14 +375,14 @@ get_syms(conf, syms)
  *     strp    -       ^ to ^ to EXPORT string table
  *     szp     -       ^ to EXPORT string table size
  */
-#define SYMBUFSIZE 262144
+#define SYMBUFSIZE 1048576
 xlate_xtok(xp, kp, strp, szp)
-     register struct syment *xp;
-     register sym_t *kp;
+     struct syment *xp;
+     sym_t *kp;
      char **strp;
      uint *szp;
 {
-    register len;
+    int len;
     static char *export_strings = NULL, *prev = "";
     static left, offset, sz;
 
@@ -420,12 +418,18 @@ xlate_xtok(xp, kp, strp, szp)
         */
        len = strlen(xstrings + xp->n_offset) + 1;
        while (len >= left) {
+           fprintf(stderr, "cfgexport: Out of memory. Increase SYMBUFSIZE and recompile\n");
+           exit(1);
+#if 0
+           /* Something is broken with this code, after being here
+              cfgexport segfaults */
            export_strings = (char *)realloc(*strp, sz += SYMBUFSIZE);
            if (!export_strings)
                error("no memory for EXPORT string table");
            *strp = export_strings;
            left += SYMBUFSIZE;
            prev = "";          /* lazy */
+#endif
        }
 
        strcpy(prev = *strp + offset, xstrings + xp->n_offset);
@@ -455,7 +459,7 @@ xlate_xtok(xp, kp, strp, szp)
         */
        len = strlen(xp->n_nptr) + 1;
        while (len >= left) {
-           export_strings = (char *)realloc(*strp, sz += SYMBUFSIZE);
+           export_strings = realloc(*strp, sz += SYMBUFSIZE);
            if (!export_strings)
                error("no memory for EXPORT string table");
            *strp = export_strings;
@@ -477,7 +481,7 @@ xlate_xtok(xp, kp, strp, szp)
     if (debug)
        dump_ksym(kp, *strp);
 }
-\f
+
 /*
  * find_suffix -       look for a string that arg string is suffix of
  *
@@ -495,11 +499,11 @@ xlate_xtok(xp, kp, strp, szp)
  *     This is rather inefficient.
  */
 find_suffix(p, strings, max, offp)
-     register char *p, *strings;
+     char *p, *strings;
      uint *offp;
 {
-    register char *q, *e;
-    register len = strlen(p) - 1;
+    char *q, *e;
+    int len = strlen(p) - 1;
 
     strings += sizeof(uint);
     max -= sizeof(uint);
@@ -529,7 +533,7 @@ find_suffix(p, strings, max, offp)
 
     return 0;
 }
-\f
+
 /*
  * xsym_compar -       compare two XCOFF symbol table entries
  *
@@ -537,10 +541,10 @@ find_suffix(p, strings, max, offp)
  * C_EXT < C_HIDEXT;
  */
 xsym_compar(xp, xq)
-     register struct syment *xp, *xq;
+     struct syment *xp, *xq;
 {
-    register char *p, *q;
-    register compar;
+    char *p, *q;
+    int compar;
 
 #ifndef __XCOFF64__
     p = (xp->n_zeroes ? xp->n_name : xp->n_nptr);
@@ -560,7 +564,7 @@ xsym_compar(xp, xq)
 
     return compar;
 }
-\f
+
 /*
  * dump_xsym - print to XCOFF symbol
  */