[BACK]Return to alloc.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / sudo

Diff for /src/usr.bin/sudo/Attic/alloc.c between version 1.5 and 1.6

version 1.5, 2003/03/15 21:23:53 version 1.6, 2003/04/03 19:15:34
Line 55 
Line 55 
 #if defined(HAVE_MALLOC_H) && !defined(STDC_HEADERS)  #if defined(HAVE_MALLOC_H) && !defined(STDC_HEADERS)
 # include <malloc.h>  # include <malloc.h>
 #endif /* HAVE_MALLOC_H && !STDC_HEADERS */  #endif /* HAVE_MALLOC_H && !STDC_HEADERS */
   #ifdef HAVE_ERR_H
   # include <err.h>
   #else
   # include "emul/err.h"
   #endif /* HAVE_ERR_H */
 #include <limits.h>  #include <limits.h>
   
 #include "sudo.h"  #include "sudo.h"
   
 #ifndef lint  #ifndef lint
 static const char rcsid[] = "$Sudo: alloc.c,v 1.18 2003/03/15 20:31:01 millert Exp $";  static const char rcsid[] = "$Sudo: alloc.c,v 1.19 2003/04/02 18:25:19 millert Exp $";
 #endif /* lint */  #endif /* lint */
   
 /*  /*
Line 81 
Line 86 
 # endif /* SIZE_T_MAX */  # endif /* SIZE_T_MAX */
 #endif /* SIZE_MAX */  #endif /* SIZE_MAX */
   
 extern char **Argv;             /* from sudo.c */  
   
 /*  /*
  * emalloc() calls the system malloc(3) and exits with an error if   * emalloc() calls the system malloc(3) and exits with an error if
  * malloc(3) fails.   * malloc(3) fails.
Line 93 
Line 96 
 {  {
     VOID *ptr;      VOID *ptr;
   
     if (size == 0) {      if (size == 0)
         (void) fprintf(stderr, "%s: internal error, tried to emalloc(0)\n",          errx(1, "internal error, tried to emalloc(0)");
             Argv[0]);  
         exit(1);      if ((ptr = (VOID *) malloc(size)) == NULL)
     }          errx(1, "unable to allocate memory");
     if ((ptr = (VOID *) malloc(size)) == NULL) {  
         (void) fprintf(stderr, "%s: cannot allocate memory!\n", Argv[0]);  
         exit(1);  
     }  
     return(ptr);      return(ptr);
 }  }
   
Line 116 
Line 115 
 {  {
     VOID *ptr;      VOID *ptr;
   
     if (nmemb == 0 || size == 0) {      if (nmemb == 0 || size == 0)
         (void) fprintf(stderr, "%s: internal error, tried to emalloc2(0)\n",          errx(1, "internal error, tried to emalloc2(0)");
             Argv[0]);      if (nmemb > SIZE_MAX / size)
         exit(1);          errx(1, "internal error, emalloc2() overflow");
     }  
     if (nmemb > SIZE_MAX / size) {  
         (void) fprintf(stderr, "%s: internal error, emalloc2() overflow\n",  
             Argv[0]);  
         exit(1);  
     }  
     size *= nmemb;      size *= nmemb;
     if ((ptr = (VOID *) malloc(size)) == NULL) {      if ((ptr = (VOID *) malloc(size)) == NULL)
         (void) fprintf(stderr, "%s: cannot allocate memory!\n", Argv[0]);          errx(1, "unable to allocate memory");
         exit(1);  
     }  
     return(ptr);      return(ptr);
 }  }
   
Line 145 
Line 137 
     size_t size;      size_t size;
 {  {
   
     if (size == 0) {      if (size == 0)
         (void) fprintf(stderr, "%s: internal error, tried to erealloc(0)\n",          errx(1, "internal error, tried to erealloc(0)");
             Argv[0]);  
         exit(1);  
     }  
     ptr = ptr ? (VOID *) realloc(ptr, size) : (VOID *) malloc(size);      ptr = ptr ? (VOID *) realloc(ptr, size) : (VOID *) malloc(size);
     if (ptr == NULL) {      if (ptr == NULL)
         (void) fprintf(stderr, "%s: cannot allocate memory!\n", Argv[0]);          errx(1, "unable to allocate memory");
         exit(1);  
     }  
     return(ptr);      return(ptr);
 }  }
   
Line 171 
Line 159 
     size_t size;      size_t size;
 {  {
   
     if (nmemb == 0 || size == 0) {      if (nmemb == 0 || size == 0)
         (void) fprintf(stderr, "%s: internal error, tried to erealloc3(0)\n",          errx(1, "internal error, tried to erealloc3(0)");
             Argv[0]);      if (nmemb > SIZE_MAX / size)
         exit(1);          errx(1, "internal error, erealloc3() overflow");
     }  
     if (nmemb > SIZE_MAX / size) {  
         (void) fprintf(stderr, "%s: internal error, erealloc3() overflow\n",  
             Argv[0]);  
         exit(1);  
     }  
     size *= nmemb;      size *= nmemb;
     ptr = ptr ? (VOID *) realloc(ptr, size) : (VOID *) malloc(size);      ptr = ptr ? (VOID *) realloc(ptr, size) : (VOID *) malloc(size);
     if (ptr == NULL) {      if (ptr == NULL)
         (void) fprintf(stderr, "%s: cannot allocate memory!\n", Argv[0]);          errx(1, "unable to allocate memory");
         exit(1);  
     }  
     return(ptr);      return(ptr);
 }  }
   
Line 236 
Line 217 
     len = vasprintf(ret, fmt, ap);      len = vasprintf(ret, fmt, ap);
     va_end(ap);      va_end(ap);
   
     if (len == -1) {      if (len == -1)
         (void) fprintf(stderr, "%s: cannot allocate memory!\n", Argv[0]);          errx(1, "unable to allocate memory");
         exit(1);  
     }  
     return(len);      return(len);
 }  }
   
Line 255 
Line 234 
 {  {
     int len;      int len;
   
     if ((len = vasprintf(ret, format, args)) == -1) {      if ((len = vasprintf(ret, format, args)) == -1)
         (void) fprintf(stderr, "%s: cannot allocate memory!\n", Argv[0]);          errx(1, "unable to allocate memory");
         exit(1);  
     }  
     return(len);      return(len);
 }  }

Legend:
Removed from v.1.5  
changed lines
  Added in v.1.6