From 37dc888fa1c1e82983e0995a4dd6e2f987db775f Mon Sep 17 00:00:00 2001 From: bostic Date: Wed, 29 Dec 1993 10:48:43 +0000 Subject: [PATCH] malloc(2) of 0 bytes isn't defined, don't allocate anything --- common/cut.c | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/common/cut.c b/common/cut.c index 1523a8e3..c54b5a50 100644 --- a/common/cut.c +++ b/common/cut.c @@ -6,7 +6,7 @@ */ #ifndef lint -static char sccsid[] = "$Id: cut.c,v 8.15 1993/12/09 19:42:03 bostic Exp $ (Berkeley) $Date: 1993/12/09 19:42:03 $"; +static char sccsid[] = "$Id: cut.c,v 8.16 1993/12/29 10:48:43 bostic Exp $ (Berkeley) $Date: 1993/12/29 10:48:43 $"; #endif /* not lint */ #include @@ -227,24 +227,21 @@ text_init(sp, p, len, total_len) MALLOC(sp, tp, TEXT *, sizeof(TEXT)); if (tp == NULL) return (NULL); - tp->lb_len = total_len; - MALLOC(sp, tp->lb, CHAR_T *, total_len); - if (tp->lb == NULL) { - FREE(tp, sizeof(TEXT)); - return (NULL); - } -#ifdef DEBUG - if (total_len) - memset(tp->lb, 0, total_len - 1); -#endif - - if (p != NULL && len != 0) - memmove(tp->lb, p, len); + /* ANSI C doesn't define a call to malloc(2) for 0 bytes. */ + if (tp->lb_len = total_len) { + MALLOC(sp, tp->lb, CHAR_T *, tp->lb_len); + if (tp->lb == NULL) { + free(tp); + return (NULL); + } + if (p != NULL && len != 0) + memmove(tp->lb, p, len); + } else + tp->lb = NULL; tp->len = len; tp->ai = tp->insert = tp->offset = tp->owrite = 0; tp->wd = NULL; tp->wd_len = 0; - return (tp); } -- 2.11.4.GIT