diff options
author | Vincent Labrecque <vincent@cvs.openbsd.org> | 2003-10-27 11:21:13 +0000 |
---|---|---|
committer | Vincent Labrecque <vincent@cvs.openbsd.org> | 2003-10-27 11:21:13 +0000 |
commit | 999b065f9ebbc179d82c564a22f1f0fd4e8f1804 (patch) | |
tree | b91c56265b8de6bc334243502eaee36fcecf0161 /usr.bin | |
parent | cb48f9d51463dff7978fe45bea2b306a53c09628 (diff) |
fix crash on startup by using the good allocation routine in edinit()
spotted and ok by henning
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/mg/def.h | 4 | ||||
-rw-r--r-- | usr.bin/mg/main.c | 11 | ||||
-rw-r--r-- | usr.bin/mg/window.c | 7 |
3 files changed, 9 insertions, 13 deletions
diff --git a/usr.bin/mg/def.h b/usr.bin/mg/def.h index 6bf7e5059b0..2e285760397 100644 --- a/usr.bin/mg/def.h +++ b/usr.bin/mg/def.h @@ -1,4 +1,4 @@ -/* $OpenBSD: def.h,v 1.49 2003/10/21 22:48:07 vincent Exp $ */ +/* $OpenBSD: def.h,v 1.50 2003/10/27 11:21:12 vincent Exp $ */ #include <sys/queue.h> @@ -360,6 +360,8 @@ int kinsert(int, int); int kremove(int); /* window.c X */ +MGWIN *new_window(BUFFER *); +void free_window(MGWIN *); int reposition(int, int); int refresh(int, int); int nextwind(int, int); diff --git a/usr.bin/mg/main.c b/usr.bin/mg/main.c index 9cc3ce3853d..568b20ed60a 100644 --- a/usr.bin/mg/main.c +++ b/usr.bin/mg/main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.25 2003/06/26 23:04:10 vincent Exp $ */ +/* $OpenBSD: main.c,v 1.26 2003/10/27 11:21:12 vincent Exp $ */ /* * Mainline. @@ -157,7 +157,7 @@ edinit(PF init_fcn) bheadp = NULL; bp = bfind("*scratch*", TRUE); /* Text buffer. */ - wp = (MGWIN *)malloc(sizeof(MGWIN)); /* Initial window. */ + wp = new_window(bp); if (wp == NULL) panic("Out of memory"); if (bp == NULL || wp == NULL) @@ -166,15 +166,8 @@ edinit(PF init_fcn) wheadp = wp; curwp = wp; wp->w_wndp = NULL; /* Initialize window. */ - wp->w_bufp = bp; - bp->b_nwnd = 1; /* Displayed. */ wp->w_linep = wp->w_dotp = bp->b_linep; - wp->w_doto = 0; - wp->w_markp = NULL; - wp->w_marko = 0; - wp->w_toprow = 0; wp->w_ntrows = nrow - 2; /* 2 = mode, echo. */ - wp->w_force = 0; wp->w_flag = WFMODE | WFHARD; /* Full. */ if (init_fcn) diff --git a/usr.bin/mg/window.c b/usr.bin/mg/window.c index 20fcf71113b..1d75d054f8c 100644 --- a/usr.bin/mg/window.c +++ b/usr.bin/mg/window.c @@ -1,4 +1,4 @@ -/* $OpenBSD: window.c,v 1.12 2003/10/21 22:48:07 vincent Exp $ */ +/* $OpenBSD: window.c,v 1.13 2003/10/27 11:21:12 vincent Exp $ */ /* * Window handling. @@ -11,7 +11,7 @@ new_window(BUFFER *bp) { MGWIN *wp; - wp = malloc(sizeof(MGWIN)); + wp = calloc(1, sizeof(MGWIN)); if (wp == NULL) return (NULL); @@ -22,7 +22,8 @@ new_window(BUFFER *bp) wp->w_marko = 0; wp->w_flag = 0; wp->w_force = 0; - bp->b_nwnd++; + if (bp) + bp->b_nwnd++; LIST_INIT(&wp->w_undo); wp->w_undoptr = NULL; memset(&wp->w_undopos, 0, sizeof wp->w_undopos); |