summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>1997-11-29 05:01:24 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>1997-11-29 05:01:24 +0000
commit16d31019ef8a4fda95fffc64ccdb8c772af08976 (patch)
tree4c9288e555d41692712cce4c652b7fc11d15ecab /lib
parent1d94037a7d1c1367be4627f319db375db12389f8 (diff)
Check malloc() return vals.
Diffstat (limited to 'lib')
-rw-r--r--lib/libcurses/hardscroll.c6
-rw-r--r--lib/libcurses/lib_color.c5
-rw-r--r--lib/libcurses/lib_doupdate.c3
-rw-r--r--lib/libcurses/lib_mvcur.c13
-rw-r--r--lib/libcurses/lib_resize.c4
-rw-r--r--lib/libcurses/lib_set_term.c3
-rw-r--r--lib/libcurses/lib_traceatr.c9
-rw-r--r--lib/libcurses/wresize.c2
8 files changed, 36 insertions, 9 deletions
diff --git a/lib/libcurses/hardscroll.c b/lib/libcurses/hardscroll.c
index 46c08343130..6da4aac9d81 100644
--- a/lib/libcurses/hardscroll.c
+++ b/lib/libcurses/hardscroll.c
@@ -360,7 +360,11 @@ void _nc_linedump(void)
int n;
char *buf;
- buf = malloc((LINES * 12) + 5); /* Assumes int is at most 32bits */
+ /* We assume an int is at most 32 bits in size. */
+ if ((buf = malloc((LINES * 12) + 5)) == NULL) {
+ errno = ENOMEM;
+ returnCode(ERR);
+ }
(void) strcpy(buf, "real");
for (n = 0; n < LINES; n++)
(void) sprintf(buf + strlen(buf), " %02d", REAL(n));
diff --git a/lib/libcurses/lib_color.c b/lib/libcurses/lib_color.c
index 68f8c6902ec..1e8dc9acf21 100644
--- a/lib/libcurses/lib_color.c
+++ b/lib/libcurses/lib_color.c
@@ -98,7 +98,10 @@ int start_color(void)
returnCode(ERR);
SP->_coloron = 1;
- SP->_color_table = malloc(sizeof(color_t) * COLORS);
+ if ((SP->_color_table = malloc(sizeof(color_t) * COLORS)) == NULL) {
+ errno = ENOMEM;
+ returnCode(ERR);
+ }
#ifdef hue_lightness_saturation
if (hue_lightness_saturation)
memcpy(SP->_color_table, hls_palette, sizeof(color_t) * COLORS);
diff --git a/lib/libcurses/lib_doupdate.c b/lib/libcurses/lib_doupdate.c
index 0c20ebd72c3..841ca48a95a 100644
--- a/lib/libcurses/lib_doupdate.c
+++ b/lib/libcurses/lib_doupdate.c
@@ -884,7 +884,8 @@ chtype blank = newscr->_line[total-1].text[last-1]; /* lower right char */
}
}
#if NO_LEAKS
- FreeAndNull(tstLine);
+ if (tstLine != 0)
+ FreeAndNull(tstLine);
#endif
return total;
}
diff --git a/lib/libcurses/lib_mvcur.c b/lib/libcurses/lib_mvcur.c
index a03a17338c7..807b6c5eeeb 100644
--- a/lib/libcurses/lib_mvcur.c
+++ b/lib/libcurses/lib_mvcur.c
@@ -1196,6 +1196,8 @@ static int roll(int n)
int main(int argc, char *argv[])
{
+ char *p;
+
(void) strncpy(tname, getenv("TERM"), sizeof(tname) - 1);
tname[sizeof(tname) - 1] = '\0';
load_term();
@@ -1208,10 +1210,15 @@ int main(int argc, char *argv[])
* Undo the effects of our optimization hack, otherwise our interactive
* prompts don't flush properly.
*/
+ if ((p = malloc(BUFSIZ)) == NULL) {
+ fprintf(stderr, "Can't allocate memory\n");
+ exit(1);
+ }
+
#if HAVE_SETVBUF
- (void) setvbuf(SP->_ofp, malloc(BUFSIZ), _IOLBF, BUFSIZ);
+ (void) setvbuf(SP->_ofp, p, _IOLBF, BUFSIZ);
#elif HAVE_SETBUFFER
- (void) setbuffer(SP->_ofp, malloc(BUFSIZ), BUFSIZ);
+ (void) setbuffer(SP->_ofp, p, BUFSIZ);
#endif
#endif /* HAVE_SETVBUF || HAVE_SETBUFFER */
@@ -1442,7 +1449,7 @@ int main(int argc, char *argv[])
_nc_mvcur_wrap();
putchar('\n');
- return(0);
+ exit(0);
}
#endif /* MAIN */
diff --git a/lib/libcurses/lib_resize.c b/lib/libcurses/lib_resize.c
index be2f199d78b..0855d3f9fb5 100644
--- a/lib/libcurses/lib_resize.c
+++ b/lib/libcurses/lib_resize.c
@@ -57,8 +57,10 @@ int wresize(WINDOW *win, int new_lines, int new_cols)
tp->text = &(win->_parent->_line[win->_pary+i].text[win->_parx]);
else /* allocate new lines if needed */
{
- if (!(tp->text = (chtype *)malloc(sizeof(chtype) * new_cols)))
+ if (!(tp->text = (chtype *)malloc(sizeof(chtype) * new_cols))) {
+ errno = ENOMEM;
return(ERR);
+ }
for (j = 0; j < new_cols; j++)
tp->text[j] = blank;
}
diff --git a/lib/libcurses/lib_set_term.c b/lib/libcurses/lib_set_term.c
index a79021906ba..ecb2bb88af1 100644
--- a/lib/libcurses/lib_set_term.c
+++ b/lib/libcurses/lib_set_term.c
@@ -72,7 +72,8 @@ void _nc_set_buffer(FILE *ofp, bool buffered)
if (buffered) {
buf_len = min(LINES * (COLS + 6), 2800);
- buf_ptr = malloc(buf_len);
+ if ((buf_ptr = malloc(buf_len)) == NULL)
+ return;
} else {
buf_len = 0;
buf_ptr = 0;
diff --git a/lib/libcurses/lib_traceatr.c b/lib/libcurses/lib_traceatr.c
index df2c1b22473..d477c501bad 100644
--- a/lib/libcurses/lib_traceatr.c
+++ b/lib/libcurses/lib_traceatr.c
@@ -51,6 +51,10 @@ char * _nc_trace_buf(int bufnum, size_t want)
size_t need = (bufnum + 1) * 2;
size_t used = sizeof(*list) * need;
list = (list == 0) ? malloc(used) : realloc(list, used);
+ if (list == 0) {
+ errno = ENOMEM;
+ return(NULL);
+ }
while (need > have)
list[have++].text = 0;
}
@@ -64,7 +68,10 @@ char * _nc_trace_buf(int bufnum, size_t want)
list[bufnum].text = realloc(list[bufnum].text, want);
list[bufnum].size = want;
}
- *(list[bufnum].text) = '\0';
+ if (list[bufnum].text != 0)
+ *(list[bufnum].text) = '\0';
+ else
+ errno = ENOMEM;
return list[bufnum].text;
}
diff --git a/lib/libcurses/wresize.c b/lib/libcurses/wresize.c
index 3d5c1f8c4d1..d50ef2f2a52 100644
--- a/lib/libcurses/wresize.c
+++ b/lib/libcurses/wresize.c
@@ -35,6 +35,8 @@ static void *doalloc(void *p, size_t n)
p = malloc(n);
else
p = realloc(p, n);
+ if (p == 0)
+ errno = ENOMEM;
return p;
}