summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>1998-08-15 18:44:48 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>1998-08-15 18:44:48 +0000
commit48794a3cba64d810b2e5ce122ccb0bc9fea78a10 (patch)
tree3ed9c033b46815f8e388b58a0a0e3dc12868f153 /lib
parent32870a3c444656dcfeda23356f1725e1bca1f944 (diff)
fix broken realloc fix from yesterday
Diffstat (limited to 'lib')
-rw-r--r--lib/libcurses/comp_expand.c21
-rw-r--r--lib/libcurses/lib_doupdate.c21
-rw-r--r--lib/libcurses/trace_buf.c4
-rw-r--r--lib/libcurses/wresize.c7
4 files changed, 26 insertions, 27 deletions
diff --git a/lib/libcurses/comp_expand.c b/lib/libcurses/comp_expand.c
index 286326d56e4..089162f149d 100644
--- a/lib/libcurses/comp_expand.c
+++ b/lib/libcurses/comp_expand.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: comp_expand.c,v 1.2 1998/08/14 21:11:38 millert Exp $ */
+/* $OpenBSD: comp_expand.c,v 1.3 1998/08/15 18:44:43 millert Exp $ */
/****************************************************************************
* Copyright (c) 1998 Free Software Foundation, Inc. *
@@ -63,17 +63,16 @@ bool islong = (strlen(str) > 3);
size_t need = (2 + strlen(str)) * 4;
int ch;
- if (buffer == 0) {
- nbuffer = malloc(length = need);
- } else if (need > length) {
- nbuffer = realloc(buffer, length = need);
- }
- if (nbuffer == 0) {
- if (buffer != 0)
- free(buffer);
- return(NULL);
+ if (buffer == 0 || need > length) {
+ length = need;
+ nbuffer = buffer ? realloc(buffer, length) : malloc(length);
+ if (nbuffer == 0) {
+ if (buffer != 0)
+ free(buffer);
+ return(NULL);
+ }
+ buffer = nbuffer;
}
- buffer = nbuffer;
bufp = 0;
ptr = str;
diff --git a/lib/libcurses/lib_doupdate.c b/lib/libcurses/lib_doupdate.c
index e13052a0cea..f9913cd0dee 100644
--- a/lib/libcurses/lib_doupdate.c
+++ b/lib/libcurses/lib_doupdate.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: lib_doupdate.c,v 1.7 1998/08/14 21:11:39 millert Exp $ */
+/* $OpenBSD: lib_doupdate.c,v 1.8 1998/08/15 18:44:44 millert Exp $ */
/****************************************************************************
* Copyright (c) 1998 Free Software Foundation, Inc. *
@@ -927,20 +927,23 @@ static size_t lenLine;
int row, col;
int top = total;
int last = min(screen_columns, newscr->_maxx+1);
+int error = 0;
size_t length = sizeof(chtype) * last;
chtype blank = newscr->_line[total-1].text[last-1]; /* lower right char */
-chtype *ntstLine;
+void *p;
- if(!clr_eos || !can_clear_with(blank))
+ if (!clr_eos || !can_clear_with(blank))
return total;
- if (tstLine == 0)
- ntstLine = (chtype *)malloc(length);
- else if (length > lenLine)
- ntstLine = (chtype *)realloc(tstLine, length);
+ if (tstLine == 0 || length > lenLine) {
+ p = tstLine ? realloc(tstLine, length) : malloc(length);
+ if (p != 0)
+ tstLine = (chtype *)p;
+ else
+ error = 1;
+ }
- if (ntstLine != 0) {
- tstLine = ntstLine;
+ if (!error) {
lenLine = length;
for (col = 0; col < last; col++)
tstLine[col] = blank;
diff --git a/lib/libcurses/trace_buf.c b/lib/libcurses/trace_buf.c
index bc15ceee441..a096fc7a9f8 100644
--- a/lib/libcurses/trace_buf.c
+++ b/lib/libcurses/trace_buf.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: trace_buf.c,v 1.3 1998/08/14 21:11:44 millert Exp $ */
+/* $OpenBSD: trace_buf.c,v 1.4 1998/08/15 18:44:46 millert Exp $ */
/****************************************************************************
* Copyright (c) 1998 Free Software Foundation, Inc. *
@@ -79,7 +79,7 @@ char * _nc_trace_buf(int bufnum, size_t want)
}
else if (want > list[bufnum].size)
{
- char *p = realloc(list[bufnum].text, want);
+ void *p = realloc(list[bufnum].text, want);
if (p != 0) {
list[bufnum].text = p;
diff --git a/lib/libcurses/wresize.c b/lib/libcurses/wresize.c
index 6d28cb0b6f9..f51d29e60e1 100644
--- a/lib/libcurses/wresize.c
+++ b/lib/libcurses/wresize.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: wresize.c,v 1.5 1998/08/14 21:11:45 millert Exp $ */
+/* $OpenBSD: wresize.c,v 1.6 1998/08/15 18:44:47 millert Exp $ */
/****************************************************************************
* Copyright (c) 1998 Free Software Foundation, Inc. *
@@ -47,10 +47,7 @@ static void *doalloc(void *p, size_t n)
{
void *np;
- if (p == 0)
- np = malloc(n);
- else
- np = realloc(p, n);
+ np = p ? realloc(p, n) : malloc(n);
if (np == 0 && p != 0)
free(p);
return np;