summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVincent Labrecque <vincent@cvs.openbsd.org>2002-07-03 03:48:00 +0000
committerVincent Labrecque <vincent@cvs.openbsd.org>2002-07-03 03:48:00 +0000
commit93345487e145c07cae35392d6302b3a01ffb6616 (patch)
treeaab9870b6078624163ed39df6cc34b7a1493ff47
parent21d2026709fc9f32e3b9ee2af9465fb459c2bb4f (diff)
a few missing tests for malloc()'s return value.
ok art@
-rw-r--r--usr.bin/mg/echo.c11
-rw-r--r--usr.bin/mg/extend.c6
-rw-r--r--usr.bin/mg/file.c4
-rw-r--r--usr.bin/mg/main.c4
4 files changed, 18 insertions, 7 deletions
diff --git a/usr.bin/mg/echo.c b/usr.bin/mg/echo.c
index a8b00847e28..728fc7a06a0 100644
--- a/usr.bin/mg/echo.c
+++ b/usr.bin/mg/echo.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: echo.c,v 1.22 2002/07/01 14:33:44 vincent Exp $ */
+/* $OpenBSD: echo.c,v 1.23 2002/07/03 03:47:59 vincent Exp $ */
/*
* Echo line reading and writing.
@@ -742,11 +742,18 @@ free_file_list(LIST *lp)
static LIST *
copy_list(LIST *lp)
{
- LIST *current, *last;
+ LIST *current, *last, *nxt;
last = NULL;
while (lp) {
current = (LIST *)malloc(sizeof(LIST));
+ if (current == NULL) {
+ for (current = last; current; current = nxt) {
+ nxt = current->l_next;
+ free(current);
+ return (NULL);
+ }
+ }
current->l_next = last;
current->l_name = lp->l_name;
last = (LIST *)current;
diff --git a/usr.bin/mg/extend.c b/usr.bin/mg/extend.c
index 43626488f20..67b764b0633 100644
--- a/usr.bin/mg/extend.c
+++ b/usr.bin/mg/extend.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: extend.c,v 1.27 2002/07/01 14:33:44 vincent Exp $ */
+/* $OpenBSD: extend.c,v 1.28 2002/07/03 03:47:59 vincent Exp $ */
/*
* Extended (M-X) commands, rebinding, and startup file processing.
@@ -189,9 +189,9 @@ remap(KEYMAP *curmap, /* pointer to the map being changed */
if (pref_map != NULL)
ele->k_prefmap = pref_map;
else {
- if (!(mp = malloc(sizeof(KEYMAP) +
+ if ((mp = malloc(sizeof(KEYMAP) +
(MAPINIT - 1) *
- sizeof(MAP_ELEMENT)))) {
+ sizeof(MAP_ELEMENT))) == NULL) {
ewprintf("Out of memory");
ele->k_funcp[c - ele->k_base] =
curmap->map_default;
diff --git a/usr.bin/mg/file.c b/usr.bin/mg/file.c
index c4cfaefea5e..6bbcf11e8ad 100644
--- a/usr.bin/mg/file.c
+++ b/usr.bin/mg/file.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: file.c,v 1.20 2002/07/01 14:33:44 vincent Exp $ */
+/* $OpenBSD: file.c,v 1.21 2002/07/03 03:47:59 vincent Exp $ */
/*
* File commands.
@@ -196,6 +196,8 @@ insertfile(char *fname, char *newname, int needinfo)
lp1 = NULL;
if (line == NULL) {
line = malloc(NLINE);
+ if (line == NULL)
+ panic("out of memory");
linesize = NLINE;
}
diff --git a/usr.bin/mg/main.c b/usr.bin/mg/main.c
index a56ba40ee75..8a5fa78ed05 100644
--- a/usr.bin/mg/main.c
+++ b/usr.bin/mg/main.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: main.c,v 1.20 2002/07/01 14:33:44 vincent Exp $ */
+/* $OpenBSD: main.c,v 1.21 2002/07/03 03:47:59 vincent Exp $ */
/*
* Mainline.
@@ -111,6 +111,8 @@ edinit(void)
bheadp = NULL;
bp = bfind("*scratch*", TRUE); /* Text buffer. */
wp = (MGWIN *)malloc(sizeof(MGWIN)); /* Initial window. */
+ if (wp == NULL)
+ panic("Out of memory");
if (bp == NULL || wp == NULL)
panic("edinit");
curbp = bp; /* Current ones. */