No need to translate "unable to allocate memory" when we can just

use the system translation via strerror().
This commit is contained in:
Todd C. Miller
2012-09-17 16:59:26 -04:00
parent f808fead0a
commit 1d90c0ad71
9 changed files with 28 additions and 26 deletions

View File

@@ -51,6 +51,7 @@
#include "missing.h"
#include "alloc.h"
#include "error.h"
#include "errno.h"
#define DEFAULT_TEXT_DOMAIN "sudo"
#include "gettext.h"
@@ -82,7 +83,7 @@ emalloc(size_t size)
errorx2(1, _("internal error, tried to emalloc(0)"));
if ((ptr = malloc(size)) == NULL)
errorx2(1, _("unable to allocate memory"));
errorx2(1, NULL);
return ptr;
}
@@ -102,7 +103,7 @@ emalloc2(size_t nmemb, size_t size)
size *= nmemb;
if ((ptr = malloc(size)) == NULL)
errorx2(1, _("unable to allocate memory"));
errorx2(1, NULL);
return ptr;
}
@@ -124,7 +125,7 @@ ecalloc(size_t nmemb, size_t size)
size *= nmemb;
}
if ((ptr = malloc(size)) == NULL)
errorx2(1, _("unable to allocate memory"));
errorx2(1, NULL);
memset(ptr, 0, size);
return ptr;
}
@@ -143,7 +144,7 @@ erealloc(void *ptr, size_t size)
ptr = ptr ? realloc(ptr, size) : malloc(size);
if (ptr == NULL)
errorx2(1, _("unable to allocate memory"));
errorx2(1, NULL);
return ptr;
}
@@ -165,7 +166,7 @@ erealloc3(void *ptr, size_t nmemb, size_t size)
size *= nmemb;
ptr = ptr ? realloc(ptr, size) : malloc(size);
if (ptr == NULL)
errorx2(1, _("unable to allocate memory"));
errorx2(1, NULL);
return ptr;
}
@@ -189,7 +190,7 @@ erecalloc(void *ptr, size_t onmemb, size_t nmemb, size_t msize)
size = nmemb * msize;
ptr = ptr ? realloc(ptr, size) : malloc(size);
if (ptr == NULL)
errorx2(1, _("unable to allocate memory"));
errorx2(1, NULL);
if (nmemb > onmemb) {
size = (nmemb - onmemb) * msize;
memset((char *)ptr + (onmemb * msize), 0, size);
@@ -253,7 +254,7 @@ easprintf(char **ret, const char *fmt, ...)
va_end(ap);
if (len == -1)
errorx2(1, _("unable to allocate memory"));
errorx2(1, strerror(ENOMEM));
return len;
}
@@ -267,7 +268,7 @@ evasprintf(char **ret, const char *format, va_list args)
int len;
if ((len = vasprintf(ret, format, args)) == -1)
errorx2(1, _("unable to allocate memory"));
errorx2(1, NULL);
return len;
}

View File

@@ -126,7 +126,7 @@ group_plugin_load(char *plugin_info)
if (ac != 0) {
argv = malloc(ac * sizeof(char *));
if (argv == NULL) {
fprintf(stderr, "unable to allocate memory\n");
perror(NULL);
return -1;
}
ac = 0;

View File

@@ -367,7 +367,7 @@ sudo_putenv(char *str, bool dupcheck, bool overwrite)
if (env.envp[env.env_len] != NULL)
errorx(1, _("sudo_putenv: corrupted envp, length mismatch"));
#endif
errorx(1, _("unable to allocate memory"));
errorx(1, NULL);
}
debug_return_int(rval);
}

View File

@@ -3416,7 +3416,7 @@ switch_dir(struct include_stack *stack, char *dirpath)
sudoerserror(errbuf);
free(errbuf);
} else {
sudoerserror(_("unable to allocate memory"));
sudoerserror(strerror(errno));
}
}
goto done;
@@ -3546,7 +3546,7 @@ _push_include(char *path, bool isdir)
istack = (struct include_stack *) realloc(istack,
sizeof(*istack) * istacksize);
if (istack == NULL) {
sudoerserror(_("unable to allocate memory"));
sudoerserror(strerror(errno));
debug_return_bool(false);
}
}
@@ -3697,7 +3697,7 @@ parse_include(char *base)
len += (int)(ep - cp);
path = pp = malloc(len + dirlen + 1);
if (path == NULL) {
sudoerserror(_("unable to allocate memory"));
sudoerserror(strerror(errno));
debug_return_str(NULL);
}
if (dirlen) {

View File

@@ -694,7 +694,7 @@ switch_dir(struct include_stack *stack, char *dirpath)
sudoerserror(errbuf);
free(errbuf);
} else {
sudoerserror(_("unable to allocate memory"));
sudoerserror(strerror(errno));
}
}
goto done;
@@ -824,7 +824,7 @@ _push_include(char *path, bool isdir)
istack = (struct include_stack *) realloc(istack,
sizeof(*istack) * istacksize);
if (istack == NULL) {
sudoerserror(_("unable to allocate memory"));
sudoerserror(strerror(errno));
debug_return_bool(false);
}
}
@@ -975,7 +975,7 @@ parse_include(char *base)
len += (int)(ep - cp);
path = pp = malloc(len + dirlen + 1);
if (path == NULL) {
sudoerserror(_("unable to allocate memory"));
sudoerserror(strerror(errno));
debug_return_str(NULL);
}
if (dirlen) {

View File

@@ -48,6 +48,7 @@
# include <malloc.h>
#endif /* HAVE_MALLOC_H && !STDC_HEADERS */
#include <ctype.h>
#include <errno.h>
#include "sudoers.h"
#include "parse.h"
@@ -110,7 +111,7 @@ fill_txt(const char *src, int len, int olen)
dst = olen ? realloc(sudoerslval.string, olen + len + 1) : malloc(len + 1);
if (dst == NULL) {
sudoerserror(_("unable to allocate memory"));
sudoerserror(strerror(errno));
debug_return_bool(false);
}
sudoerslval.string = dst;
@@ -164,7 +165,7 @@ fill_cmnd(const char *src, int len)
dst = sudoerslval.command.cmnd = (char *) malloc(len + 1);
if (sudoerslval.command.cmnd == NULL) {
sudoerserror(_("unable to allocate memory"));
sudoerserror(strerror(errno));
debug_return_bool(false);
}
@@ -204,7 +205,7 @@ fill_args(const char *s, int len, int addspace)
(char *) malloc(arg_size);
if (p == NULL) {
efree(sudoerslval.command.args);
sudoerserror(_("unable to allocate memory"));
sudoerserror(strerror(errno));
debug_return_bool(false);
} else
sudoerslval.command.args = p;

View File

@@ -109,7 +109,7 @@ disable_execute(char *const envp[])
preload = fmt_string(RTLD_PRELOAD_VAR, sudo_conf_noexec_path());
# endif
if (preload == NULL)
errorx(1, _("unable to allocate memory"));
errorx(1, NULL);
nenvp[env_len++] = preload;
nenvp[env_len] = NULL;
} else {

View File

@@ -427,7 +427,7 @@ parse_args(int argc, char **argv, int *nargc, char ***nargv, char ***settingsp,
settings[j] = fmt_string(sudo_settings[i].name,
sudo_settings[i].value);
if (settings[j] == NULL)
errorx(1, _("unable to allocate memory"));
errorx(1, NULL);
j++;
}
}

View File

@@ -453,7 +453,7 @@ get_user_info(struct user_details *ud)
user_info[i] = fmt_string("user", pw->pw_name);
if (user_info[i] == NULL)
errorx(1, _("unable to allocate memory"));
errorx(1, NULL);
ud->username = user_info[i] + sizeof("user=") - 1;
/* Stash user's shell for use with the -s flag; don't pass to plugin. */
@@ -479,14 +479,14 @@ get_user_info(struct user_details *ud)
if (getcwd(cwd, sizeof(cwd)) != NULL) {
user_info[++i] = fmt_string("cwd", cwd);
if (user_info[i] == NULL)
errorx(1, _("unable to allocate memory"));
errorx(1, NULL);
ud->cwd = user_info[i] + sizeof("cwd=") - 1;
}
if ((cp = get_process_ttyname()) != NULL) {
user_info[++i] = fmt_string("tty", cp);
if (user_info[i] == NULL)
errorx(1, _("unable to allocate memory"));
errorx(1, NULL);
ud->tty = user_info[i] + sizeof("tty=") - 1;
efree(cp);
}
@@ -497,7 +497,7 @@ get_user_info(struct user_details *ud)
strlcpy(host, "localhost", sizeof(host));
user_info[++i] = fmt_string("host", host);
if (user_info[i] == NULL)
errorx(1, _("unable to allocate memory"));
errorx(1, NULL);
ud->host = user_info[i] + sizeof("host=") - 1;
get_ttysize(&ud->ts_lines, &ud->ts_cols);
@@ -756,7 +756,7 @@ command_info_to_details(char * const info[], struct command_details *details)
#endif
details->pw = getpwuid(details->euid);
if (details->pw != NULL && (details->pw = pw_dup(details->pw)) == NULL)
errorx(1, _("unable to allocate memory"));
errorx(1, NULL);
#ifdef HAVE_SETAUTHDB
aix_restoreauthdb();
#endif