This is a theoretical issue really, as if we're having issues allocating a few bytes, then the system will likely be hosed anyway. But for correctness and to aid static analysis...
commit 85c6205f4366edc0d2c50c7036d559acc457509d Author: Pádraig Brady <[email protected]> Date: Thu May 5 15:20:13 2011 +0100 df: fix crash in mem exhaustion edge case * src/df.c (print_table): Don't try to output NULL if ambsalign() can't allocate memory. Instead just output the unaligned text. diff --git a/src/df.c b/src/df.c index 14f0790..a2675da 100644 --- a/src/df.c +++ b/src/df.c @@ -215,7 +215,7 @@ print_table (void) { size_t width = widths[field]; char *cell = table[row][field]; - if (!cell) + if (!cell) /* Missing type column, or mount point etc. */ continue; /* Note the DEV_FIELD used to be displayed on it's own line @@ -227,9 +227,11 @@ print_table (void) fputs (cell, stdout); else { - cell = ambsalign (table[row][field], &width, - alignments[field], MBA_UNIBYTE_FALLBACK); - fputs (cell, stdout); + cell = ambsalign (cell, &width, alignments[field], 0); + if (!cell) /* Output unaligned data */ + fputs (table[row][field], stdout); + else + fputs (cell, stdout); free (cell); } IF_LINT (free (table[row][field]));
