Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/libedit kill ptr_t and ioctl_t, add * sizeof(*foo) to a...



details:   https://anonhg.NetBSD.org/src/rev/b0d951a0e797
branches:  trunk
changeset: 767743:b0d951a0e797
user:      christos <christos%NetBSD.org@localhost>
date:      Thu Jul 28 20:50:55 2011 +0000

description:
kill ptr_t and ioctl_t, add  * sizeof(*foo) to all allocations.

diffstat:

 lib/libedit/chared.c       |   19 +++---
 lib/libedit/chartype.c     |    8 +-
 lib/libedit/el.c           |   22 ++++----
 lib/libedit/eln.c          |    6 +-
 lib/libedit/filecomplete.c |   54 +++++++++++---------
 lib/libedit/hist.c         |   10 +-
 lib/libedit/hist.h         |   10 +-
 lib/libedit/histedit.h     |    4 +-
 lib/libedit/history.c      |   90 +++++++++++++++++-----------------
 lib/libedit/keymacro.c     |   16 +++---
 lib/libedit/map.c          |   36 ++++++------
 lib/libedit/read.c         |   10 +-
 lib/libedit/readline.c     |  116 +++++++++++++++++++++++---------------------
 lib/libedit/search.c       |    8 +-
 lib/libedit/sig.c          |    6 +-
 lib/libedit/sys.h          |   16 +-----
 lib/libedit/terminal.c     |   56 ++++++++++++---------
 lib/libedit/tokenizer.c    |   26 +++++-----
 lib/libedit/vi.c           |    8 +-
 19 files changed, 263 insertions(+), 258 deletions(-)

diffs (truncated from 1715 to 300 lines):

diff -r 4325971d5815 -r b0d951a0e797 lib/libedit/chared.c
--- a/lib/libedit/chared.c      Thu Jul 28 20:30:06 2011 +0000
+++ b/lib/libedit/chared.c      Thu Jul 28 20:50:55 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: chared.c,v 1.30 2011/07/28 01:05:20 christos Exp $     */
+/*     $NetBSD: chared.c,v 1.31 2011/07/28 20:50:55 christos Exp $     */
 
 /*-
  * Copyright (c) 1992, 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)chared.c   8.1 (Berkeley) 6/4/93";
 #else
-__RCSID("$NetBSD: chared.c,v 1.30 2011/07/28 01:05:20 christos Exp $");
+__RCSID("$NetBSD: chared.c,v 1.31 2011/07/28 20:50:55 christos Exp $");
 #endif
 #endif /* not lint && not SCCSID */
 
@@ -544,7 +544,7 @@
 {
        c_macro_t *ma = &el->el_chared.c_macro;
        while (ma->level >= 0)
-               el_free((ptr_t)ma->macro[ma->level--]);
+               el_free(ma->macro[ma->level--]);
 }
 
 /* ch_enlargebufs():
@@ -589,7 +589,8 @@
        /*
         * Reallocate kill buffer.
         */
-       newbuffer = el_realloc(el->el_chared.c_kill.buf, newsz * sizeof(*newbuffer));
+       newbuffer = el_realloc(el->el_chared.c_kill.buf, newsz *
+           sizeof(*newbuffer));
        if (!newbuffer)
                return 0;
 
@@ -642,20 +643,20 @@
 protected void
 ch_end(EditLine *el)
 {
-       el_free((ptr_t) el->el_line.buffer);
+       el_free(el->el_line.buffer);
        el->el_line.buffer = NULL;
        el->el_line.limit = NULL;
-       el_free((ptr_t) el->el_chared.c_undo.buf);
+       el_free(el->el_chared.c_undo.buf);
        el->el_chared.c_undo.buf = NULL;
-       el_free((ptr_t) el->el_chared.c_redo.buf);
+       el_free(el->el_chared.c_redo.buf);
        el->el_chared.c_redo.buf = NULL;
        el->el_chared.c_redo.pos = NULL;
        el->el_chared.c_redo.lim = NULL;
        el->el_chared.c_redo.cmd = ED_UNASSIGNED;
-       el_free((ptr_t) el->el_chared.c_kill.buf);
+       el_free(el->el_chared.c_kill.buf);
        el->el_chared.c_kill.buf = NULL;
        ch_reset(el, 1);
-       el_free((ptr_t) el->el_chared.c_macro.macro);
+       el_free(el->el_chared.c_macro.macro);
        el->el_chared.c_macro.macro = NULL;
 }
 
diff -r 4325971d5815 -r b0d951a0e797 lib/libedit/chartype.c
--- a/lib/libedit/chartype.c    Thu Jul 28 20:30:06 2011 +0000
+++ b/lib/libedit/chartype.c    Thu Jul 28 20:50:55 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: chartype.c,v 1.6 2011/07/28 00:48:21 christos Exp $    */
+/*     $NetBSD: chartype.c,v 1.7 2011/07/28 20:50:55 christos Exp $    */
 
 /*-
  * Copyright (c) 2009 The NetBSD Foundation, Inc.
@@ -38,7 +38,7 @@
  */
 #include "config.h"
 #if !defined(lint) && !defined(SCCSID)
-__RCSID("$NetBSD: chartype.c,v 1.6 2011/07/28 00:48:21 christos Exp $");
+__RCSID("$NetBSD: chartype.c,v 1.7 2011/07/28 20:50:55 christos Exp $");
 #endif /* not lint && not SCCSID */
 #include "el.h"
 #include <stdlib.h>
@@ -52,7 +52,7 @@
        void *p;
        if (mincsize > conv->csize) {
                conv->csize = mincsize;
-               p = el_realloc(conv->cbuff, conv->csize * sizeof(char));
+               p = el_realloc(conv->cbuff, conv->csize * sizeof(*conv->cbuff));
                if (p == NULL) {
                        conv->csize = 0;
                        el_free(conv->cbuff);
@@ -63,7 +63,7 @@
 
        if (minwsize > conv->wsize) {
                conv->wsize = minwsize;
-               p = el_realloc(conv->wbuff, conv->wsize * sizeof(Char));
+               p = el_realloc(conv->wbuff, conv->wsize * sizeof(*conv->wbuff));
                if (p == NULL) {
                        conv->wsize = 0;
                        el_free(conv->wbuff);
diff -r 4325971d5815 -r b0d951a0e797 lib/libedit/el.c
--- a/lib/libedit/el.c  Thu Jul 28 20:30:06 2011 +0000
+++ b/lib/libedit/el.c  Thu Jul 28 20:50:55 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: el.c,v 1.66 2011/07/28 01:56:27 christos Exp $ */
+/*     $NetBSD: el.c,v 1.67 2011/07/28 20:50:55 christos Exp $ */
 
 /*-
  * Copyright (c) 1992, 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)el.c       8.2 (Berkeley) 1/3/94";
 #else
-__RCSID("$NetBSD: el.c,v 1.66 2011/07/28 01:56:27 christos Exp $");
+__RCSID("$NetBSD: el.c,v 1.67 2011/07/28 20:50:55 christos Exp $");
 #endif
 #endif /* not lint && not SCCSID */
 
@@ -60,7 +60,7 @@
 public EditLine *
 el_init(const char *prog, FILE *fin, FILE *fout, FILE *ferr)
 {
-       EditLine *el = (EditLine *) el_malloc(sizeof(EditLine));
+       EditLine *el = el_malloc(sizeof(*el));
 
        if (el == NULL)
                return (NULL);
@@ -134,14 +134,14 @@
        prompt_end(el);
        sig_end(el);
 
-       el_free((ptr_t) el->el_prog);
+       el_free(el->el_prog);
 #ifdef WIDECHAR
-       el_free((ptr_t) el->el_scratch.cbuff);
-       el_free((ptr_t) el->el_scratch.wbuff);
-       el_free((ptr_t) el->el_lgcyconv.cbuff);
-       el_free((ptr_t) el->el_lgcyconv.wbuff);
+       el_free(el->el_scratch.cbuff);
+       el_free(el->el_scratch.wbuff);
+       el_free(el->el_lgcyconv.cbuff);
+       el_free(el->el_lgcyconv.wbuff);
 #endif
-       el_free((ptr_t) el);
+       el_free(el);
 }
 
 
@@ -270,7 +270,7 @@
        case EL_HIST:
        {
                hist_fun_t func = va_arg(ap, hist_fun_t);
-               ptr_t ptr = va_arg(ap, ptr_t);
+               void *ptr = va_arg(ap, void *);
 
                rv = hist_set(el, func, ptr);
                if (!(el->el_flags & CHARSET_IS_UTF8))
@@ -521,7 +521,7 @@
                if ((ptr = getenv("HOME")) == NULL)
                        return (-1);
                plen += strlen(ptr);
-               if ((path = malloc(plen)) == NULL)
+               if ((path = el_malloc(plen * sizeof(*path))) == NULL)
                        return (-1);
                (void)snprintf(path, plen, "%s%s", ptr, elpath);
                fname = path;
diff -r 4325971d5815 -r b0d951a0e797 lib/libedit/eln.c
--- a/lib/libedit/eln.c Thu Jul 28 20:30:06 2011 +0000
+++ b/lib/libedit/eln.c Thu Jul 28 20:50:55 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: eln.c,v 1.11 2011/07/28 01:05:20 christos Exp $        */
+/*     $NetBSD: eln.c,v 1.12 2011/07/28 20:50:55 christos Exp $        */
 
 /*-
  * Copyright (c) 2009 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
  */
 #include "config.h"
 #if !defined(lint) && !defined(SCCSID)
-__RCSID("$NetBSD: eln.c,v 1.11 2011/07/28 01:05:20 christos Exp $");
+__RCSID("$NetBSD: eln.c,v 1.12 2011/07/28 20:50:55 christos Exp $");
 #endif /* not lint && not SCCSID */
 
 #include "histedit.h"
@@ -215,7 +215,7 @@
        }
        case EL_HIST: {           /* hist_fun_t, const char * */
                hist_fun_t fun = va_arg(ap, hist_fun_t);
-               ptr_t ptr = va_arg(ap, ptr_t);
+               void *ptr = va_arg(ap, void *);
                ret = hist_set(el, fun, ptr);
                el->el_flags |= NARROW_HISTORY;
                break;
diff -r 4325971d5815 -r b0d951a0e797 lib/libedit/filecomplete.c
--- a/lib/libedit/filecomplete.c        Thu Jul 28 20:30:06 2011 +0000
+++ b/lib/libedit/filecomplete.c        Thu Jul 28 20:50:55 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: filecomplete.c,v 1.25 2011/07/28 17:33:55 christos Exp $       */
+/*     $NetBSD: filecomplete.c,v 1.26 2011/07/28 20:50:55 christos Exp $       */
 
 /*-
  * Copyright (c) 1997 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include "config.h"
 #if !defined(lint) && !defined(SCCSID)
-__RCSID("$NetBSD: filecomplete.c,v 1.25 2011/07/28 17:33:55 christos Exp $");
+__RCSID("$NetBSD: filecomplete.c,v 1.26 2011/07/28 20:50:55 christos Exp $");
 #endif /* not lint && not SCCSID */
 
 #include <sys/types.h>
@@ -91,7 +91,7 @@
                        return NULL;
        } else {
                len = temp - txt + 1;   /* text until string after slash */
-               temp = malloc(len);
+               temp = el_malloc(len * sizeof(*temp));
                if (temp == NULL)
                        return NULL;
                (void)strncpy(temp, txt + 1, len - 2);
@@ -117,7 +117,7 @@
                pass = getpwnam(temp);
 #endif
        }
-       free(temp);             /* value no more needed */
+       el_free(temp);          /* value no more needed */
        if (pass == NULL)
                return (strdup(txt));
 
@@ -125,10 +125,11 @@
        /* first slash */
        txt += len;
 
-       temp = malloc(strlen(pass->pw_dir) + 1 + strlen(txt) + 1);
+       len = strlen(pass->pw_dir) + 1 + strlen(txt) + 1;
+       temp = el_malloc(len * sizeof(*temp));
        if (temp == NULL)
                return NULL;
-       (void)sprintf(temp, "%s/%s", pass->pw_dir, txt);
+       (void)snprintf(temp, len, "%s/%s", pass->pw_dir, txt);
 
        return (temp);
 }
@@ -156,9 +157,10 @@
                if (temp) {
                        char *nptr;
                        temp++;
-                       nptr = realloc(filename, strlen(temp) + 1);
+                       nptr = el_realloc(filename, (strlen(temp) + 1) *
+                           sizeof(*nptr));
                        if (nptr == NULL) {
-                               free(filename);
+                               el_free(filename);
                                filename = NULL;
                                return NULL;
                        }
@@ -166,9 +168,10 @@
                        (void)strcpy(filename, temp);
                        len = temp - text;      /* including last slash */
 
-                       nptr = realloc(dirname, len + 1);
+                       nptr = el_realloc(dirname, (len + 1) *
+                           sizeof(*nptr));
                        if (nptr == NULL) {
-                               free(dirname);
+                               el_free(dirname);
                                dirname = NULL;
                                return NULL;
                        }
@@ -176,7 +179,7 @@
                        (void)strncpy(dirname, text, len);
                        dirname[len] = '\0';
                } else {
-                       free(filename);
+                       el_free(filename);
                        if (*text == 0)
                                filename = NULL;
                        else {
@@ -184,7 +187,7 @@
                                if (filename == NULL)
                                        return NULL;
                        }
-                       free(dirname);
+                       el_free(dirname);
                        dirname = NULL;
                }
 
@@ -195,7 +198,7 @@
 
                /* support for ``~user'' syntax */
 
-               free(dirpath);
+               el_free(dirpath);
                dirpath = NULL;
                if (dirname == NULL) {
                        if ((dirname = strdup("")) == NULL)
@@ -246,10 +249,11 @@
                len = strlen(entry->d_name);
 #endif
 
-               temp = malloc(strlen(dirname) + len + 1);



Home | Main Index | Thread Index | Old Index