Don't cast the return from realloc()
[openafs.git] / src / export / cfgexport.c
index 4acca1f..2eae231 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.
      */
@@ -202,6 +200,8 @@ get_syms(conf, syms)
     FILE *fp;
     int xsym_compar();
 
+    if (syms == NULL)
+      sys_error("syms is NULL");
     fp = fopen(syms, "r");
     if (fp == NULL)
        sys_error(syms);
@@ -375,24 +375,25 @@ get_syms(conf, syms)
  *     strp    -       ^ to ^ to EXPORT string table
  *     szp     -       ^ to EXPORT string table size
  */
+#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;
 
     if (!export_strings) {
-       export_strings = malloc(sz = 1024);
+       export_strings = malloc(sz = SYMBUFSIZE);
        if (!export_strings)
            error("no memory for EXPORT string table");
 
        *strp = export_strings;
        *szp = offset = sizeof(uint);
-       left = 1024 - offset;
+       left = SYMBUFSIZE - offset;
 
        export_strings += offset;
 
@@ -417,12 +418,18 @@ xlate_xtok(xp, kp, strp, szp)
         */
        len = strlen(xstrings + xp->n_offset) + 1;
        while (len >= left) {
-           export_strings = (char *)realloc(*strp, sz += 1024);
+           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 += 1024;
+           left += SYMBUFSIZE;
            prev = "";          /* lazy */
+#endif
        }
 
        strcpy(prev = *strp + offset, xstrings + xp->n_offset);
@@ -452,11 +459,11 @@ xlate_xtok(xp, kp, strp, szp)
         */
        len = strlen(xp->n_nptr) + 1;
        while (len >= left) {
-           export_strings = (char *)realloc(*strp, sz += 1024);
+           export_strings = realloc(*strp, sz += SYMBUFSIZE);
            if (!export_strings)
                error("no memory for EXPORT string table");
            *strp = export_strings;
-           left += 1024;
+           left += SYMBUFSIZE;
            prev = "";          /* lazy */
        }
 
@@ -474,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
  *
@@ -492,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);
@@ -526,7 +533,7 @@ find_suffix(p, strings, max, offp)
 
     return 0;
 }
-\f
+
 /*
  * xsym_compar -       compare two XCOFF symbol table entries
  *
@@ -534,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);
@@ -557,7 +564,7 @@ xsym_compar(xp, xq)
 
     return compar;
 }
-\f
+
 /*
  * dump_xsym - print to XCOFF symbol
  */