diff options
author | Ted Unangst <tedu@cvs.openbsd.org> | 2015-09-01 13:12:32 +0000 |
---|---|---|
committer | Ted Unangst <tedu@cvs.openbsd.org> | 2015-09-01 13:12:32 +0000 |
commit | 7fffd18f58839f079048dbc1ef5ac199a709b13d (patch) | |
tree | 666bed69f5dc7607a894dd63d798484f39a28a45 | |
parent | e75a4737e7e5686910f3af279fc62c313c1c4cd5 (diff) |
remove casts and null checks before free. from Michael McConville
ok deraadt
-rw-r--r-- | bin/ksh/c_ksh.c | 8 | ||||
-rw-r--r-- | bin/ksh/edit.c | 4 | ||||
-rw-r--r-- | bin/ksh/emacs.c | 7 | ||||
-rw-r--r-- | bin/ksh/expand.h | 6 | ||||
-rw-r--r-- | bin/ksh/history.c | 8 | ||||
-rw-r--r-- | bin/ksh/mail.c | 10 | ||||
-rw-r--r-- | bin/ksh/syn.c | 6 | ||||
-rw-r--r-- | bin/ksh/table.c | 6 | ||||
-rw-r--r-- | bin/ksh/tree.c | 22 | ||||
-rw-r--r-- | bin/ksh/var.c | 26 | ||||
-rw-r--r-- | bin/ksh/vi.c | 4 |
11 files changed, 50 insertions, 57 deletions
diff --git a/bin/ksh/c_ksh.c b/bin/ksh/c_ksh.c index f89afef7ff7..273c0679de6 100644 --- a/bin/ksh/c_ksh.c +++ b/bin/ksh/c_ksh.c @@ -1,4 +1,4 @@ -/* $OpenBSD: c_ksh.c,v 1.34 2013/12/17 16:37:05 deraadt Exp $ */ +/* $OpenBSD: c_ksh.c,v 1.35 2015/09/01 13:12:31 tedu Exp $ */ /* * built-in Korn commands: c_* @@ -943,7 +943,7 @@ c_alias(char **wp) if ((val && !tflag) || (!val && tflag && !Uflag)) { if (ap->flag&ALLOC) { ap->flag &= ~(ALLOC|ISSET); - afree((void*)ap->val.s, APERM); + afree(ap->val.s, APERM); } /* ignore values for -t (at&t ksh does this) */ newval = tflag ? search(alias, path, X_OK, (int *) 0) : @@ -998,7 +998,7 @@ c_unalias(char **wp) } if (ap->flag&ALLOC) { ap->flag &= ~(ALLOC|ISSET); - afree((void*)ap->val.s, APERM); + afree(ap->val.s, APERM); } ap->flag &= ~(DEFINED|ISSET|EXPORT); } @@ -1009,7 +1009,7 @@ c_unalias(char **wp) for (ktwalk(&ts, t); (ap = ktnext(&ts)); ) { if (ap->flag&ALLOC) { ap->flag &= ~(ALLOC|ISSET); - afree((void*)ap->val.s, APERM); + afree(ap->val.s, APERM); } ap->flag &= ~(DEFINED|ISSET|EXPORT); } diff --git a/bin/ksh/edit.c b/bin/ksh/edit.c index b049f6c11e2..3eed072deb1 100644 --- a/bin/ksh/edit.c +++ b/bin/ksh/edit.c @@ -1,4 +1,4 @@ -/* $OpenBSD: edit.c,v 1.40 2015/03/12 10:20:30 sthen Exp $ */ +/* $OpenBSD: edit.c,v 1.41 2015/09/01 13:12:31 tedu Exp $ */ /* * Command line editing - common code @@ -489,7 +489,7 @@ x_command_glob(int flags, const char *str, int slen, char ***wordsp) path_order_cmp); for (i = 0; i < nwords; i++) words[i] = info[i].word; - afree((void *) info, ATEMP); + afree(info, ATEMP); } else { /* Sort and remove duplicate entries */ char **words = (char **) XPptrv(w); diff --git a/bin/ksh/emacs.c b/bin/ksh/emacs.c index 72333eb1152..9a929dd43e0 100644 --- a/bin/ksh/emacs.c +++ b/bin/ksh/emacs.c @@ -1,4 +1,4 @@ -/* $OpenBSD: emacs.c,v 1.50 2015/03/25 12:10:52 jca Exp $ */ +/* $OpenBSD: emacs.c,v 1.51 2015/09/01 13:12:31 tedu Exp $ */ /* * Emacs-like command line editing and history @@ -1149,7 +1149,7 @@ x_push(int nchars) { char *cp = str_nsave(xcp, nchars, AEDIT); if (killstack[killsp]) - afree((void *)killstack[killsp], AEDIT); + afree(killstack[killsp], AEDIT); killstack[killsp] = cp; killsp = (killsp + 1) % KILLSIZE; } @@ -1307,8 +1307,7 @@ static void kb_del(struct kb_entry *k) { TAILQ_REMOVE(&kblist, k, entry); - if (k->args) - free(k->args); + free(k->args); afree(k, AEDIT); } diff --git a/bin/ksh/expand.h b/bin/ksh/expand.h index 7288d4de1a3..5ea1a0ed874 100644 --- a/bin/ksh/expand.h +++ b/bin/ksh/expand.h @@ -1,4 +1,4 @@ -/* $OpenBSD: expand.h,v 1.6 2005/03/30 17:16:37 deraadt Exp $ */ +/* $OpenBSD: expand.h,v 1.7 2015/09/01 13:12:31 tedu Exp $ */ /* * Expanding strings @@ -55,7 +55,7 @@ typedef char * XStringP; #define Xcheck(xs, xp) XcheckN(xs, xp, 1) /* free string */ -#define Xfree(xs, xp) afree((void*) (xs).beg, (xs).areap) +#define Xfree(xs, xp) afree((xs).beg, (xs).areap) /* close, return string */ #define Xclose(xs, xp) (char*) aresize((void*)(xs).beg, \ @@ -104,4 +104,4 @@ typedef struct XPtrV { #define XPclose(x) (void**) aresize((void*)(x).beg, \ sizeofN(void*, XPsize(x)), ATEMP) -#define XPfree(x) afree((void*) (x).beg, ATEMP) +#define XPfree(x) afree((x).beg, ATEMP) diff --git a/bin/ksh/history.c b/bin/ksh/history.c index 92021378be3..25f7c56314f 100644 --- a/bin/ksh/history.c +++ b/bin/ksh/history.c @@ -1,4 +1,4 @@ -/* $OpenBSD: history.c,v 1.40 2014/11/20 15:22:39 tedu Exp $ */ +/* $OpenBSD: history.c,v 1.41 2015/09/01 13:12:31 tedu Exp $ */ /* * command history @@ -417,7 +417,7 @@ histbackup(void) if (histptr >= history && last_line != hist_source->line) { hist_source->line--; - afree((void*)*histptr, APERM); + afree(*histptr, APERM); histptr--; last_line = hist_source->line; } @@ -589,7 +589,7 @@ histsave(int lno, const char *cmd, int dowrite) hp = histptr; if (++hp >= history + histsize) { /* remove oldest command */ - afree((void*)*history, APERM); + afree(*history, APERM); for (hp = history; hp < history + histsize - 1; hp++) hp[0] = hp[1]; } @@ -872,7 +872,7 @@ histinsert(Source *s, int lno, unsigned char *line) if (lno >= s->line-(histptr-history) && lno <= s->line) { hp = &histptr[lno-s->line]; if (*hp) - afree((void*)*hp, APERM); + afree(*hp, APERM); *hp = str_save((char *)line, APERM); } } diff --git a/bin/ksh/mail.c b/bin/ksh/mail.c index d5a51c0df76..73878f83fca 100644 --- a/bin/ksh/mail.c +++ b/bin/ksh/mail.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mail.c,v 1.17 2013/11/28 10:33:37 sobrado Exp $ */ +/* $OpenBSD: mail.c,v 1.18 2015/09/01 13:12:31 tedu Exp $ */ /* * Mailbox checking code by Robert J. Gibson, adapted for PD ksh by @@ -90,9 +90,9 @@ mbset(char *p) struct stat stbuf; if (mbox.mb_msg) - afree((void *)mbox.mb_msg, APERM); + afree(mbox.mb_msg, APERM); if (mbox.mb_path) - afree((void *)mbox.mb_path, APERM); + afree(mbox.mb_path, APERM); /* Save a copy to protect from export (which munges the string) */ mbox.mb_path = str_save(p, APERM); mbox.mb_msg = NULL; @@ -151,8 +151,8 @@ munset(mbox_t *mlist) mbp = mlist; mlist = mbp->mb_next; if (!mlist) - afree((void *)mbp->mb_path, APERM); - afree((void *)mbp, APERM); + afree(mbp->mb_path, APERM); + afree(mbp, APERM); } } diff --git a/bin/ksh/syn.c b/bin/ksh/syn.c index 2e92489de40..6167ba92d2f 100644 --- a/bin/ksh/syn.c +++ b/bin/ksh/syn.c @@ -1,4 +1,4 @@ -/* $OpenBSD: syn.c,v 1.29 2013/06/03 18:40:05 jca Exp $ */ +/* $OpenBSD: syn.c,v 1.30 2015/09/01 13:12:31 tedu Exp $ */ /* * shell parser (C version) @@ -206,7 +206,7 @@ get_command(int cf) switch (c = token(cf|KEYWORD|ALIAS|VARASN)) { default: REJECT; - afree((void*) iops, ATEMP); + afree(iops, ATEMP); XPfree(args); XPfree(vars); return NULL; /* empty line */ @@ -385,7 +385,7 @@ get_command(int cf) } if (iopn == 0) { - afree((void*) iops, ATEMP); + afree(iops, ATEMP); t->ioact = NULL; } else { iops[iopn++] = NULL; diff --git a/bin/ksh/table.c b/bin/ksh/table.c index 74d16847341..497cf405864 100644 --- a/bin/ksh/table.c +++ b/bin/ksh/table.c @@ -1,4 +1,4 @@ -/* $OpenBSD: table.c,v 1.15 2012/02/19 07:52:30 otto Exp $ */ +/* $OpenBSD: table.c,v 1.16 2015/09/01 13:12:31 tedu Exp $ */ /* * dynamic hashed associative table for commands and variables @@ -58,10 +58,10 @@ texpand(struct table *tp, int nsize) *p = tblp; tp->nfree--; } else if (!(tblp->flag & FINUSE)) { - afree((void*)tblp, tp->areap); + afree(tblp, tp->areap); } } - afree((void*)otblp, tp->areap); + afree(otblp, tp->areap); } /* table */ diff --git a/bin/ksh/tree.c b/bin/ksh/tree.c index 127c1e3678b..500c1bbe1dc 100644 --- a/bin/ksh/tree.c +++ b/bin/ksh/tree.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tree.c,v 1.20 2012/06/27 07:17:19 otto Exp $ */ +/* $OpenBSD: tree.c,v 1.21 2015/09/01 13:12:31 tedu Exp $ */ /* * command tree climbing @@ -666,18 +666,18 @@ tfree(struct op *t, Area *ap) return; if (t->str != NULL) - afree((void*)t->str, ap); + afree(t->str, ap); if (t->vars != NULL) { for (w = t->vars; *w != NULL; w++) - afree((void*)*w, ap); - afree((void*)t->vars, ap); + afree(*w, ap); + afree(t->vars, ap); } if (t->args != NULL) { for (w = t->args; *w != NULL; w++) - afree((void*)*w, ap); - afree((void*)t->args, ap); + afree(*w, ap); + afree(t->args, ap); } if (t->ioact != NULL) @@ -686,7 +686,7 @@ tfree(struct op *t, Area *ap) tfree(t->left, ap); tfree(t->right, ap); - afree((void*)t, ap); + afree(t, ap); } static void @@ -697,12 +697,12 @@ iofree(struct ioword **iow, Area *ap) for (iop = iow; (p = *iop++) != NULL; ) { if (p->name != NULL) - afree((void*)p->name, ap); + afree(p->name, ap); if (p->delim != NULL) - afree((void*)p->delim, ap); + afree(p->delim, ap); if (p->heredoc != NULL) - afree((void*)p->heredoc, ap); - afree((void*)p, ap); + afree(p->heredoc, ap); + afree(p, ap); } afree(iow, ap); } diff --git a/bin/ksh/var.c b/bin/ksh/var.c index 50ecf519d7b..916b0fa4f92 100644 --- a/bin/ksh/var.c +++ b/bin/ksh/var.c @@ -1,4 +1,4 @@ -/* $OpenBSD: var.c,v 1.42 2015/08/19 16:05:46 deraadt Exp $ */ +/* $OpenBSD: var.c,v 1.43 2015/09/01 13:12:31 tedu Exp $ */ #include "sh.h" #include <time.h> @@ -366,7 +366,7 @@ setstr(struct tbl *vq, const char *s, int error_ok) internal_errorf(true, "setstr: %s=%s: assigning to self", vq->name, s); - afree((void*)vq->val.s, vq->areap); + afree(vq->val.s, vq->areap); } vq->flag &= ~(ISSET|ALLOC); vq->type = 0; @@ -385,8 +385,7 @@ setstr(struct tbl *vq, const char *s, int error_ok) vq->flag |= ISSET; if ((vq->flag&SPECIAL)) setspec(vq); - if (fs) - afree((char *)fs, ATEMP); + afree((void *)fs, ATEMP); return 1; } @@ -576,8 +575,7 @@ export(struct tbl *vp, const char *val) *xp++ = '='; vp->type = xp - vp->val.s; /* offset to value */ memcpy(xp, val, vallen); - if (op != NULL) - afree((void*)op, vp->areap); + afree(op, vp->areap); } /* @@ -698,14 +696,12 @@ typeset(const char *var, Tflag set, Tflag clr, int field, int base) t->flag &= ~ISSET; else { if (t->flag & ALLOC) - afree((void*) t->val.s, - t->areap); + afree(t->val.s, t->areap); t->flag &= ~(ISSET|ALLOC); t->type = 0; } } - if (free_me) - afree((void *) free_me, t->areap); + afree(free_me, t->areap); } } if (!ok) @@ -739,7 +735,7 @@ void unset(struct tbl *vp, int array_ref) { if (vp->flag & ALLOC) - afree((void*)vp->val.s, vp->areap); + afree(vp->val.s, vp->areap); if ((vp->flag & ARRAY) && !array_ref) { struct tbl *a, *tmp; @@ -748,7 +744,7 @@ unset(struct tbl *vp, int array_ref) tmp = a; a = a->u.array; if (tmp->flag & ALLOC) - afree((void *) tmp->val.s, tmp->areap); + afree(tmp->val.s, tmp->areap); afree(tmp, tmp->areap); } vp->u.array = (struct tbl *) 0; @@ -952,8 +948,7 @@ setspec(struct tbl *vp) switch (special(vp->name)) { case V_PATH: - if (path) - afree(path, APERM); + afree(path, APERM); path = str_save(str_val(vp), APERM); flushcom(1); /* clear tracked aliases */ break; @@ -1059,8 +1054,7 @@ unsetspec(struct tbl *vp) { switch (special(vp->name)) { case V_PATH: - if (path) - afree(path, APERM); + afree(path, APERM); path = str_save(def_path, APERM); flushcom(1); /* clear tracked aliases */ break; diff --git a/bin/ksh/vi.c b/bin/ksh/vi.c index b31d4af9362..9c53fc2d50f 100644 --- a/bin/ksh/vi.c +++ b/bin/ksh/vi.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vi.c,v 1.28 2013/12/18 16:45:46 deraadt Exp $ */ +/* $OpenBSD: vi.c,v 1.29 2015/09/01 13:12:31 tedu Exp $ */ /* * vi command editing @@ -1401,7 +1401,7 @@ static void free_edstate(struct edstate *old) { afree(old->cbuf, APERM); - afree((char *)old, APERM); + afree(old, APERM); } |