1
0
mirror of https://github.com/slicer69/doas synced 2024-07-09 03:55:50 +00:00

Change realloc() back to reallocarray()

This commit is contained in:
Tobias Kortkamp 2016-06-24 13:29:08 +02:00
parent ef6ff75f22
commit 64ab988d34
4 changed files with 6 additions and 16 deletions

View File

@ -2,7 +2,7 @@ CC?=clang
YC?=yacc
BIN=doas
PREFIX?=/usr/local
OBJECTS=doas.o env.o execvpe.o y.tab.o
OBJECTS=doas.o env.o execvpe.o reallocarray.o y.tab.o
CFLAG+= -DUSE_PAM
LFLAG+= -lpam

6
doas.h
View File

@ -27,11 +27,7 @@ char **prepenv(struct rule *);
#define _PW_NAME_LEN 32
#endif
#if !defined(HAVE_REALLOCARRAY) && !defined(HAVE_REALLOCARR)
int reallocarr(void *ptr, size_t num, size_t size);
#endif /* !HAVE_REALLOCARRAY && !HAVE_REALLOCARR */
void *reallocarray(void *ptr, size_t nmemb, size_t size);
#if !defined(HAVE_EXECVPE)
int execvpe(const char *file, char * const *argv, char * const *envp);

2
env.c
View File

@ -95,7 +95,7 @@ flattenenv(struct env *env)
struct envnode *node;
u_int i;
envp = realloc(NULL, (env->count + 1) * sizeof(char *));
envp = reallocarray(NULL, (env->count + 1), sizeof(char *));
if (!envp)
err(1, NULL);
i = 0;

12
parse.y
View File

@ -84,10 +84,8 @@ rule: action ident target cmd {
maxrules = 63;
else
maxrules *= 2;
/* if (!(rules = reallocarray(rules, maxrules,
if (!(rules = reallocarray(rules, maxrules,
sizeof(*rules))))
*/
if (!(rules = realloc(rules, maxrules * sizeof(*rules))))
errx(1, "can't allocate rules");
}
rules[nrules++] = r;
@ -127,10 +125,8 @@ envlist: /* empty */ {
errx(1, "can't allocate envlist");
} | envlist TSTRING {
int nenv = arraylen($1.envlist);
/* if (!($$.envlist = reallocarray($1.envlist, nenv + 2,
if (!($$.envlist = reallocarray($1.envlist, nenv + 2,
sizeof(char *))))
*/
if (!($$.envlist = realloc($1.envlist, (nenv + 2) * sizeof(char*))))
errx(1, "can't allocate envlist");
$$.envlist[nenv] = $2.str;
$$.envlist[nenv + 1] = NULL;
@ -166,10 +162,8 @@ argslist: /* empty */ {
errx(1, "can't allocate args");
} | argslist TSTRING {
int nargs = arraylen($1.cmdargs);
/* if (!($$.cmdargs = reallocarray($1.cmdargs, nargs + 2,
if (!($$.cmdargs = reallocarray($1.cmdargs, nargs + 2,
sizeof(char *))))
*/
if (!($$.cmdargs = realloc($1.cmdargs, (nargs + 2) * sizeof(char *))))
errx(1, "can't allocate args");
$$.cmdargs[nargs] = $2.str;
$$.cmdargs[nargs + 1] = NULL;