From 689181723718f7339b26abdbef5546c03db862b9 Mon Sep 17 00:00:00 2001 From: David Rhodus Date: Tue, 4 Nov 2003 15:55:22 +0000 Subject: [PATCH] * Handle realloc() failure correctly. Obtained from: The FreeBSD project --- bin/ls/print.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/bin/ls/print.c b/bin/ls/print.c index b234c67a87..22bff2b93b 100644 --- a/bin/ls/print.c +++ b/bin/ls/print.c @@ -35,7 +35,7 @@ * * @(#)print.c 8.4 (Berkeley) 4/17/94 * $FreeBSD: src/bin/ls/print.c,v 1.19.2.7 2002/11/17 10:27:34 tjr Exp $ - * $DragonFly: src/bin/ls/print.c,v 1.2 2003/06/17 04:22:50 dillon Exp $ + * $DragonFly: src/bin/ls/print.c,v 1.3 2003/11/04 15:55:22 drhodus Exp $ */ #include @@ -246,6 +246,7 @@ printcol(DISPLAY *dp) static FTSENT **array; static int lastentries = -1; FTSENT *p; + FTSENT **narray; int base; int chcnt; int cnt; @@ -269,11 +270,14 @@ printcol(DISPLAY *dp) */ if (dp->entries > lastentries) { lastentries = dp->entries; - if ((array = + if ((narray = realloc(array, dp->entries * sizeof(FTSENT *))) == NULL) { warn(NULL); printscol(dp); + return; } + lastentries = dp->entries; + array = narray; } for (p = dp->list, num = 0; p; p = p->fts_link) if (p->fts_number != NO_PRINT) -- 2.41.0