diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 2003-04-16 02:38:19 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 2003-04-16 02:38:19 +0000 |
commit | 7835e1b8b359e0fae3d111e2100a4dbda4c24029 (patch) | |
tree | 095e01c516fe30806153fd13b565fb948f2bfc33 /usr.bin/mg | |
parent | 510a389031957312e00143ce4969fc4af1e3888b (diff) |
lalloc() - return NULL on error, not FALSE
lrealloc() - don't realloc if new size <= old size. Avoids a realloc(p, 0)
vincent@ OK
Diffstat (limited to 'usr.bin/mg')
-rw-r--r-- | usr.bin/mg/line.c | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/usr.bin/mg/line.c b/usr.bin/mg/line.c index 29ef7a1bb01..eb7cdddce81 100644 --- a/usr.bin/mg/line.c +++ b/usr.bin/mg/line.c @@ -1,4 +1,4 @@ -/* $OpenBSD: line.c,v 1.17 2002/07/01 14:33:44 vincent Exp $ */ +/* $OpenBSD: line.c,v 1.18 2003/04/16 02:38:18 millert Exp $ */ /* * Text line handling. @@ -52,7 +52,7 @@ lalloc(int used) LINE *lp; if ((lp = malloc(sizeof *lp)) == NULL) - return FALSE; + return NULL; lp->l_text = NULL; lp->l_size = 0; lp->l_used = used; /* XXX */ @@ -68,10 +68,12 @@ lrealloc(LINE *lp, int newsize) { char *tmp; - if ((tmp = realloc(lp->l_text, newsize)) == NULL) - return FALSE; - lp->l_text = tmp; - lp->l_size = newsize; + if (lp->l_size < newsize) { + if ((tmp = realloc(lp->l_text, newsize)) == NULL) + return FALSE; + lp->l_text = tmp; + lp->l_size = newsize; + } return TRUE; } |