From 7f5855dc00905546eba6e62ce5907da713fbf4c0 Mon Sep 17 00:00:00 2001 From: espie Date: Fri, 23 Jan 2015 13:18:40 +0000 Subject: [PATCH] remove a bunch of dangerous casts (useless casts from void * to something else, in some cases by adding extra temporary variables. IMO, it's much better practice to do void *a; int *p = a; *p = 42; rather than void *a; *(int *)a = 42; okay miod@... to be revisited for some possible const additions later. --- usr.bin/make/compat.c | 6 +++--- usr.bin/make/dir.c | 10 ++++++---- usr.bin/make/direxpand.c | 5 +++-- usr.bin/make/dump.c | 4 ++-- usr.bin/make/engine.c | 4 ++-- usr.bin/make/for.c | 6 +++--- usr.bin/make/main.c | 6 +++--- usr.bin/make/make.c | 16 +++++++++------- usr.bin/make/parse.c | 10 +++++----- usr.bin/make/suff.c | 10 +++++----- usr.bin/make/varmodifiers.c | 29 +++++++++++++++-------------- 11 files changed, 56 insertions(+), 50 deletions(-) diff --git a/usr.bin/make/compat.c b/usr.bin/make/compat.c index fe538c4c53d..c6c362cf85f 100644 --- a/usr.bin/make/compat.c +++ b/usr.bin/make/compat.c @@ -1,4 +1,4 @@ -/* $OpenBSD: compat.c,v 1.83 2013/06/20 19:48:32 espie Exp $ */ +/* $OpenBSD: compat.c,v 1.84 2015/01/23 13:18:40 espie Exp $ */ /* $NetBSD: compat.c,v 1.14 1996/11/06 17:59:01 christos Exp $ */ /* @@ -71,8 +71,8 @@ static void CompatMake(void *gnp, /* The node to make */ void *pgnp) /* Parent to abort if necessary */ { - GNode *gn = (GNode *)gnp; - GNode *pgn = (GNode *)pgnp; + GNode *gn = gnp; + GNode *pgn = gnp; GNode *sib; bool cmdsOk; diff --git a/usr.bin/make/dir.c b/usr.bin/make/dir.c index 4e9ef7bbc91..3ad73c9499e 100644 --- a/usr.bin/make/dir.c +++ b/usr.bin/make/dir.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dir.c,v 1.65 2015/01/16 15:36:29 deraadt Exp $ */ +/* $OpenBSD: dir.c,v 1.66 2015/01/23 13:18:40 espie Exp $ */ /* $NetBSD: dir.c,v 1.14 1997/03/29 16:51:26 christos Exp $ */ /* @@ -642,14 +642,15 @@ Dir_AddDiri(Lst path, const char *name, const char *ename) void * Dir_CopyDir(void *p) { - ((struct PathEntry *)p)->refCount++; + struct PathEntry *q = p; + q->refCount++; return p; } void Dir_Destroy(void *pp) { - struct PathEntry *p = (struct PathEntry *)pp; + struct PathEntry *p = pp; if (--p->refCount == 0) { ohash_remove(&knownDirectories, @@ -685,7 +686,8 @@ Dir_Concat(Lst path1, Lst path2) static void DirPrintDir(void *p) { - printf("%s ", ((struct PathEntry *)p)->name); + struct PathEntry *q = p; + printf("%s ", q->name); } void diff --git a/usr.bin/make/direxpand.c b/usr.bin/make/direxpand.c index 1ce71951c5b..db29246b7a3 100644 --- a/usr.bin/make/direxpand.c +++ b/usr.bin/make/direxpand.c @@ -1,4 +1,4 @@ -/* $OpenBSD: direxpand.c,v 1.5 2010/07/19 19:30:37 espie Exp $ */ +/* $OpenBSD: direxpand.c,v 1.6 2015/01/23 13:18:40 espie Exp $ */ /* * Copyright (c) 1999,2007 Marc Espie. * @@ -298,7 +298,8 @@ Dir_Expandi(const char *word, const char *eword, Lst path, Lst expansions) static void DirPrintWord(void *word) { - printf("%s ", (char *)word); + char *s = word; + printf("%s ", s); } diff --git a/usr.bin/make/dump.c b/usr.bin/make/dump.c index 3b688f74c9e..accba322f83 100644 --- a/usr.bin/make/dump.c +++ b/usr.bin/make/dump.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dump.c,v 1.6 2014/05/18 08:08:50 espie Exp $ */ +/* $OpenBSD: dump.c,v 1.7 2015/01/23 13:18:40 espie Exp $ */ /* * Copyright (c) 2012 Marc Espie. * @@ -82,7 +82,7 @@ sort_ohash(struct ohash *h, int (*comparison)(const void *, const void *)) static void TargPrintName(void *gnp) { - GNode *gn = (GNode *)gnp; + GNode *gn = gnp; printf("%s ", gn->name); } diff --git a/usr.bin/make/engine.c b/usr.bin/make/engine.c index 541765d7cb7..734135efe37 100644 --- a/usr.bin/make/engine.c +++ b/usr.bin/make/engine.c @@ -1,4 +1,4 @@ -/* $OpenBSD: engine.c,v 1.49 2014/10/31 13:29:42 gsoares Exp $ */ +/* $OpenBSD: engine.c,v 1.50 2015/01/23 13:18:40 espie Exp $ */ /* * Copyright (c) 2012 Marc Espie. * @@ -427,7 +427,7 @@ Make_DoAllVar(GNode *gn) static void MakeTimeStamp(void *parent, void *child) { - Make_TimeStamp((GNode *)parent, (GNode *)child); + Make_TimeStamp(parent, child); } bool diff --git a/usr.bin/make/for.c b/usr.bin/make/for.c index 9613acbfb89..64887d5e769 100644 --- a/usr.bin/make/for.c +++ b/usr.bin/make/for.c @@ -1,4 +1,4 @@ -/* $OpenBSD: for.c,v 1.45 2013/11/22 15:47:35 espie Exp $ */ +/* $OpenBSD: for.c,v 1.46 2015/01/23 13:18:40 espie Exp $ */ /* $NetBSD: for.c,v 1.4 1996/11/06 17:59:05 christos Exp $ */ /* @@ -244,8 +244,8 @@ For_Accumulate(For *arg, const char *line) static void ForExec(void *valuep, void *argp) { - char *value = (char *)valuep; - For *arg = (For *)argp; + char *value = valuep; + For *arg = argp; BUFFER buf; /* Parse_FromString pushes stuff back, so we need to go over vars in diff --git a/usr.bin/make/main.c b/usr.bin/make/main.c index b6a172f8144..fc2c498d947 100644 --- a/usr.bin/make/main.c +++ b/usr.bin/make/main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.106 2015/01/16 15:36:30 deraadt Exp $ */ +/* $OpenBSD: main.c,v 1.107 2015/01/23 13:18:40 espie Exp $ */ /* $NetBSD: main.c,v 1.34 1997/03/24 20:56:36 gwr Exp $ */ /* @@ -803,8 +803,8 @@ main(int argc, char **argv) static bool ReadMakefile(void *p, void *q) { - char *fname = (char *)p; /* makefile to read */ - struct dirs *d = (struct dirs *)q; + char *fname = p; /* makefile to read */ + struct dirs *d = q; FILE *stream; char *name; diff --git a/usr.bin/make/make.c b/usr.bin/make/make.c index ad5807a4129..de4ee8ac2eb 100644 --- a/usr.bin/make/make.c +++ b/usr.bin/make/make.c @@ -1,4 +1,4 @@ -/* $OpenBSD: make.c,v 1.68 2014/01/06 12:21:45 espie Exp $ */ +/* $OpenBSD: make.c,v 1.69 2015/01/23 13:18:40 espie Exp $ */ /* $NetBSD: make.c,v 1.10 1996/11/06 17:59:15 christos Exp $ */ /* @@ -434,8 +434,9 @@ MakePrintStatus( * a cycle in the graph, not an error in an * inferior */ { - GNode *gn = (GNode *)gnp; - bool cycle = *(bool *)cyclep; + GNode *gn = gnp; + bool *cp = cyclep; + bool cycle = *cp; if (gn->built_status == UPTODATE) { printf("`%s' is up to date.\n", gn->name); } else if (gn->unmade != 0) { @@ -471,17 +472,18 @@ MakePrintStatus( static void MakeAddChild(void *to_addp, void *ap) { - GNode *gn = (GNode *)to_addp; + GNode *gn = to_addp; + struct growableArray *a = ap; if (!gn->must_make && !(gn->type & OP_USE)) - Array_Push((struct growableArray *)ap, gn); + Array_Push(a, gn); } static void MakeHandleUse(void *cgnp, void *pgnp) { - GNode *cgn = (GNode *)cgnp; - GNode *pgn = (GNode *)pgnp; + GNode *cgn = cgnp; + GNode *pgn = pgnp; if (cgn->type & OP_USE) Make_HandleUse(cgn, pgn); diff --git a/usr.bin/make/parse.c b/usr.bin/make/parse.c index 2f8edc7fba1..bf506b58036 100644 --- a/usr.bin/make/parse.c +++ b/usr.bin/make/parse.c @@ -1,4 +1,4 @@ -/* $OpenBSD: parse.c,v 1.110 2013/11/22 15:47:35 espie Exp $ */ +/* $OpenBSD: parse.c,v 1.111 2015/01/23 13:18:40 espie Exp $ */ /* $NetBSD: parse.c,v 1.29 1997/03/10 21:20:04 christos Exp $ */ /* @@ -478,7 +478,7 @@ ParseDoSrc( static int ParseFindMain(void *gnp, void *dummy UNUSED) { - GNode *gn = (GNode *)gnp; + GNode *gn = gnp; if ((gn->type & OP_NOTARGET) == 0 && gn->special == SPECIAL_NONE) { mainNode = gn; return 0; @@ -496,7 +496,7 @@ ParseFindMain(void *gnp, void *dummy UNUSED) static void ParseClearPath(void *p) { - Lst path = (Lst)p; + Lst path = p; Lst_Destroy(path, Dir_Destroy); Lst_Init(path); @@ -998,7 +998,7 @@ ParseDoDependency(const char *line) /* the line to parse */ static void ParseAddCmd(void *gnp, void *cmd) { - GNode *gn = (GNode *)gnp; + GNode *gn = gnp; if (!(gn->type & OP_HAS_COMMANDS)) Lst_AtEnd(&gn->commands, cmd); @@ -1016,7 +1016,7 @@ ParseAddCmd(void *gnp, void *cmd) static void ParseHasCommands(void *gnp) { - GNode *gn = (GNode *)gnp; + GNode *gn = gnp; gn->type |= OP_HAS_COMMANDS; } diff --git a/usr.bin/make/suff.c b/usr.bin/make/suff.c index 8c4b56f82e2..359657295cc 100644 --- a/usr.bin/make/suff.c +++ b/usr.bin/make/suff.c @@ -1,4 +1,4 @@ -/* $OpenBSD: suff.c,v 1.88 2014/05/12 19:11:19 espie Exp $ */ +/* $OpenBSD: suff.c,v 1.89 2015/01/23 13:18:40 espie Exp $ */ /* $NetBSD: suff.c,v 1.13 1996/11/06 17:59:25 christos Exp $ */ /* @@ -679,8 +679,8 @@ SuffAddSrc( void *sp, /* suffix for which to create a Src structure */ void *lsp) /* list and parent for the new Src */ { - Suff *s = (Suff *)sp; - LstSrc *ls = (LstSrc *)lsp; + Suff *s = sp; + LstSrc *ls = lsp; Src *s2; /* new Src structure */ Src *targ; /* Target structure */ @@ -1712,14 +1712,14 @@ Suff_Init(void) static void SuffPrintName(void *p) { - Suff *s = (Suff *)p; + Suff *s = p; printf("%s ", s == emptySuff ? "" : s->name); } static void SuffPrintSuff(void *sp) { - Suff *s = (Suff *)sp; + Suff *s = sp; printf("# %-5s ", s->name); diff --git a/usr.bin/make/varmodifiers.c b/usr.bin/make/varmodifiers.c index 19dac732e22..48f69c09a70 100644 --- a/usr.bin/make/varmodifiers.c +++ b/usr.bin/make/varmodifiers.c @@ -1,4 +1,4 @@ -/* $OpenBSD: varmodifiers.c,v 1.39 2014/09/21 13:43:25 espie Exp $ */ +/* $OpenBSD: varmodifiers.c,v 1.40 2015/01/23 13:18:40 espie Exp $ */ /* $NetBSD: var.c,v 1.18 1997/03/18 19:24:46 christos Exp $ */ /* @@ -391,7 +391,7 @@ VarNoMatch(struct Name *word, bool addSpace, Buffer buf, static bool VarUniq(struct Name *word, bool addSpace, Buffer buf, void *lastp) { - struct Name *last = (struct Name *)lastp; + struct Name *last = lastp; /* does not match */ if (last->s == NULL || last->e - last->s != word->e - word->s || @@ -409,7 +409,7 @@ VarUniq(struct Name *word, bool addSpace, Buffer buf, void *lastp) static bool VarLoop(struct Name *word, bool addSpace, Buffer buf, void *vp) { - struct LoopStuff *v = (struct LoopStuff *)vp; + struct LoopStuff *v = vp; if (addSpace) Buf_AddSpace(buf); @@ -420,7 +420,7 @@ VarLoop(struct Name *word, bool addSpace, Buffer buf, void *vp) static char * finish_loop(const char *s, const struct Name *n UNUSED , void *p) { - struct LoopStuff *l = (struct LoopStuff *)p; + struct LoopStuff *l = p; return Var_Subst(s, NULL, l->err); } @@ -514,7 +514,7 @@ do_path(const char *s UNUSED, const struct Name *n, void *arg UNUSED) static char * do_def(const char *s, const struct Name *n UNUSED, void *arg) { - VarPattern *v = (VarPattern *)arg; + VarPattern *v = arg; if (s == NULL) { free_patternarg(v); return NULL; @@ -525,7 +525,7 @@ do_def(const char *s, const struct Name *n UNUSED, void *arg) static char * do_undef(const char *s, const struct Name *n UNUSED, void *arg) { - VarPattern *v = (VarPattern *)arg; + VarPattern *v = arg; if (s != NULL) { free_patternarg(v); return NULL; @@ -536,7 +536,7 @@ do_undef(const char *s, const struct Name *n UNUSED, void *arg) static char * do_assign(const char *s, const struct Name *n, void *arg) { - VarPattern *v = (VarPattern *)arg; + VarPattern *v = arg; char *msg; char *result; @@ -570,7 +570,7 @@ do_assign(const char *s, const struct Name *n, void *arg) static char * do_exec(const char *s UNUSED, const struct Name *n UNUSED, void *arg) { - VarPattern *v = (VarPattern *)arg; + VarPattern *v = arg; char *msg; char *result; @@ -592,7 +592,7 @@ VarSYSVMatch(struct Name *word, bool addSpace, Buffer buf, void *patp) { size_t len; const char *ptr; - VarPattern *pat = (VarPattern *)patp; + VarPattern *pat = patp; if (*word->s != '\0') { if (addSpace) @@ -682,7 +682,7 @@ VarSubstitute(struct Name *word, bool addSpace, Buffer buf, { size_t wordLen; /* Length of word */ const char *cp; /* General pointer */ - VarPattern *pattern = (VarPattern *)patternp; + VarPattern *pattern = patternp; wordLen = word->e - word->s; if ((pattern->flags & (VAR_SUB_ONE|VAR_SUB_MATCHED)) != @@ -1072,7 +1072,8 @@ VarGetPattern(SymTable *ctxt, int err, const char **tstr, int delim1, static char * VarQuote(const char *str, const struct Name *n UNUSED, void *islistp) { - int islist = *((int *)islistp); + int *p = islistp; + int islist = *p; BUFFER buf; /* This should cover most shells :-( */ @@ -1224,7 +1225,7 @@ get_spatternarg(const char **p, SymTable *ctxt, bool err, int endc) static void free_looparg(void *arg) { - struct LoopStuff *l = (struct LoopStuff *)arg; + struct LoopStuff *l = arg; Var_DeleteLoopVar(l->var); free(l->expand); @@ -1388,7 +1389,7 @@ get_cmd(const char **p, SymTable *ctxt, bool err, int endc UNUSED) static void free_patternarg(void *p) { - VarPattern *vp = (VarPattern *)p; + VarPattern *vp = p; free(vp->lbuffer); free(vp->rhs); @@ -1400,7 +1401,7 @@ static char * do_regex(const char *s, const struct Name *n UNUSED, void *arg) { VarREPattern p2; - VarPattern *p = (VarPattern *)arg; + VarPattern *p = arg; int error; char *result; -- 2.20.1