version 1.1.1.2, 2012/05/29 12:26:49
|
version 1.1.1.5, 2013/10/14 07:56:33
|
Line 1
|
Line 1
|
/* |
/* |
* Copyright (c) 1999-2005, 2007, 2010-2011 | * Copyright (c) 1999-2005, 2007, 2010-2013 |
* Todd C. Miller <Todd.Miller@courtesan.com> |
* Todd C. Miller <Todd.Miller@courtesan.com> |
* |
* |
* Permission to use, copy, modify, and distribute this software for any |
* Permission to use, copy, modify, and distribute this software for any |
Line 22
|
Line 22
|
#include <config.h> |
#include <config.h> |
|
|
#include <sys/types.h> |
#include <sys/types.h> |
#include <sys/param.h> |
|
#include <stdio.h> |
#include <stdio.h> |
#ifdef STDC_HEADERS |
#ifdef STDC_HEADERS |
# include <stdlib.h> |
# include <stdlib.h> |
Line 50
|
Line 49
|
|
|
#include "missing.h" |
#include "missing.h" |
#include "alloc.h" |
#include "alloc.h" |
#include "error.h" | #include "fatal.h" |
|
|
#define DEFAULT_TEXT_DOMAIN "sudo" |
#define DEFAULT_TEXT_DOMAIN "sudo" |
#include "gettext.h" |
#include "gettext.h" |
Line 79 emalloc(size_t size)
|
Line 78 emalloc(size_t size)
|
void *ptr; |
void *ptr; |
|
|
if (size == 0) |
if (size == 0) |
errorx2(1, _("internal error, tried to emalloc(0)")); | fatalx_nodebug(_("internal error, tried to emalloc(0)")); |
|
|
if ((ptr = malloc(size)) == NULL) |
if ((ptr = malloc(size)) == NULL) |
errorx2(1, _("unable to allocate memory")); | fatal_nodebug(NULL); |
return ptr; |
return ptr; |
} |
} |
|
|
Line 96 emalloc2(size_t nmemb, size_t size)
|
Line 95 emalloc2(size_t nmemb, size_t size)
|
void *ptr; |
void *ptr; |
|
|
if (nmemb == 0 || size == 0) |
if (nmemb == 0 || size == 0) |
errorx2(1, _("internal error, tried to emalloc2(0)")); | fatalx_nodebug(_("internal error, tried to emalloc2(0)")); |
if (nmemb > SIZE_MAX / size) |
if (nmemb > SIZE_MAX / size) |
errorx2(1, _("internal error, emalloc2() overflow")); | fatalx_nodebug(_("internal error, %s overflow"), "emalloc2()"); |
|
|
size *= nmemb; |
size *= nmemb; |
if ((ptr = malloc(size)) == NULL) |
if ((ptr = malloc(size)) == NULL) |
errorx2(1, _("unable to allocate memory")); | fatal_nodebug(NULL); |
return ptr; |
return ptr; |
} |
} |
|
|
Line 117 ecalloc(size_t nmemb, size_t size)
|
Line 116 ecalloc(size_t nmemb, size_t size)
|
void *ptr; |
void *ptr; |
|
|
if (nmemb == 0 || size == 0) |
if (nmemb == 0 || size == 0) |
errorx2(1, _("internal error, tried to ecalloc(0)")); | fatalx_nodebug(_("internal error, tried to ecalloc(0)")); |
if (nmemb != 1) { |
if (nmemb != 1) { |
if (nmemb > SIZE_MAX / size) |
if (nmemb > SIZE_MAX / size) |
errorx2(1, _("internal error, ecalloc() overflow")); | fatalx_nodebug(_("internal error, %s overflow"), "ecalloc()"); |
size *= nmemb; |
size *= nmemb; |
} |
} |
if ((ptr = malloc(size)) == NULL) |
if ((ptr = malloc(size)) == NULL) |
errorx2(1, _("unable to allocate memory")); | fatal_nodebug(NULL); |
memset(ptr, 0, size); |
memset(ptr, 0, size); |
return ptr; |
return ptr; |
} |
} |
Line 139 erealloc(void *ptr, size_t size)
|
Line 138 erealloc(void *ptr, size_t size)
|
{ |
{ |
|
|
if (size == 0) |
if (size == 0) |
errorx2(1, _("internal error, tried to erealloc(0)")); | fatalx_nodebug(_("internal error, tried to erealloc(0)")); |
|
|
ptr = ptr ? realloc(ptr, size) : malloc(size); |
ptr = ptr ? realloc(ptr, size) : malloc(size); |
if (ptr == NULL) |
if (ptr == NULL) |
errorx2(1, _("unable to allocate memory")); | fatal_nodebug(NULL); |
return ptr; |
return ptr; |
} |
} |
|
|
Line 158 erealloc3(void *ptr, size_t nmemb, size_t size)
|
Line 157 erealloc3(void *ptr, size_t nmemb, size_t size)
|
{ |
{ |
|
|
if (nmemb == 0 || size == 0) |
if (nmemb == 0 || size == 0) |
errorx2(1, _("internal error, tried to erealloc3(0)")); | fatalx_nodebug(_("internal error, tried to erealloc3(0)")); |
if (nmemb > SIZE_MAX / size) |
if (nmemb > SIZE_MAX / size) |
errorx2(1, _("internal error, erealloc3() overflow")); | fatalx_nodebug(_("internal error, %s overflow"), "erealloc3()"); |
|
|
size *= nmemb; |
size *= nmemb; |
ptr = ptr ? realloc(ptr, size) : malloc(size); |
ptr = ptr ? realloc(ptr, size) : malloc(size); |
if (ptr == NULL) |
if (ptr == NULL) |
errorx2(1, _("unable to allocate memory")); | fatal_nodebug(NULL); |
return ptr; |
return ptr; |
} |
} |
|
|
Line 182 erecalloc(void *ptr, size_t onmemb, size_t nmemb, size
|
Line 181 erecalloc(void *ptr, size_t onmemb, size_t nmemb, size
|
size_t size; |
size_t size; |
|
|
if (nmemb == 0 || msize == 0) |
if (nmemb == 0 || msize == 0) |
errorx2(1, _("internal error, tried to erealloc3(0)")); | fatalx_nodebug(_("internal error, tried to erecalloc(0)")); |
if (nmemb > SIZE_MAX / msize) |
if (nmemb > SIZE_MAX / msize) |
errorx2(1, _("internal error, erealloc3() overflow")); | fatalx_nodebug(_("internal error, %s overflow"), "erecalloc()"); |
|
|
size = nmemb * msize; |
size = nmemb * msize; |
ptr = ptr ? realloc(ptr, size) : malloc(size); |
ptr = ptr ? realloc(ptr, size) : malloc(size); |
if (ptr == NULL) |
if (ptr == NULL) |
errorx2(1, _("unable to allocate memory")); | fatal_nodebug(NULL); |
if (nmemb > onmemb) { |
if (nmemb > onmemb) { |
size = (nmemb - onmemb) * msize; |
size = (nmemb - onmemb) * msize; |
memset((char *)ptr + (onmemb * msize), 0, size); |
memset((char *)ptr + (onmemb * msize), 0, size); |
Line 248 easprintf(char **ret, const char *fmt, ...)
|
Line 247 easprintf(char **ret, const char *fmt, ...)
|
{ |
{ |
int len; |
int len; |
va_list ap; |
va_list ap; |
|
|
va_start(ap, fmt); |
va_start(ap, fmt); |
len = vasprintf(ret, fmt, ap); |
len = vasprintf(ret, fmt, ap); |
va_end(ap); |
va_end(ap); |
|
|
if (len == -1) |
if (len == -1) |
errorx2(1, _("unable to allocate memory")); | fatal_nodebug(NULL); |
return len; |
return len; |
} |
} |
|
|
Line 267 evasprintf(char **ret, const char *format, va_list arg
|
Line 267 evasprintf(char **ret, const char *format, va_list arg
|
int len; |
int len; |
|
|
if ((len = vasprintf(ret, format, args)) == -1) |
if ((len = vasprintf(ret, format, args)) == -1) |
errorx2(1, _("unable to allocate memory")); | fatal_nodebug(NULL); |
return len; |
return len; |
} |
|
|
|
/* |
|
* Wrapper for free(3) so we can depend on C89 semantics. |
|
*/ |
|
void |
|
efree(void *ptr) |
|
{ |
|
if (ptr != NULL) |
|
free(ptr); |
|
} |
} |