diff options
author | Cojocaru Alexandru <xojoc@gmx.com> | 2012-12-06 03:03:41 +0100 |
---|---|---|
committer | Pádraig Brady <P@draigBrady.com> | 2012-12-06 18:29:23 +0000 |
commit | ec48beadfa0ae1216788eaf6bf558ee2013eac18 (patch) | |
tree | 91642fbcf559a72c1cb8b3140a45fe91a84ab9a9 /src | |
parent | 00743a1f6e18ab5dfd6957eca638d4f670326f9b (diff) | |
download | coreutils-ec48beadfa0ae1216788eaf6bf558ee2013eac18.tar.xz |
cut: avoid a redundant heap allocation
* src/cut.c (set_fields): Don't allocate memory for
`printable_field' if there are no finite ranges.
This is achieved by keeping max_range_endpoint as 0 when
there are no finite ranges. max_range_endpoint is then
used throughout the code to guard against allocation of,
and access to the bit array.
The extra allocation was introduced via commit v8.10-3-g2e636af.
Diffstat (limited to 'src')
-rw-r--r-- | src/cut.c | 8 |
1 files changed, 4 insertions, 4 deletions
@@ -500,14 +500,13 @@ set_fields (const char *fieldstr) if (rp[i].hi > max_range_endpoint) max_range_endpoint = rp[i].hi; } - if (max_range_endpoint < eol_range_start) - max_range_endpoint = eol_range_start; /* Allocate an array large enough so that it may be indexed by the field numbers corresponding to all finite ranges (i.e. '2-6' or '-4', but not '5-') in FIELDSTR. */ - printable_field = xzalloc (max_range_endpoint / CHAR_BIT + 1); + if (max_range_endpoint) + printable_field = xzalloc (max_range_endpoint / CHAR_BIT + 1); qsort (rp, n_rp, sizeof (rp[0]), compare_ranges); @@ -531,7 +530,8 @@ set_fields (const char *fieldstr) if (output_delimiter_specified && !complement - && eol_range_start && !is_printable_field (eol_range_start)) + && eol_range_start + && max_range_endpoint && !is_printable_field (eol_range_start)) mark_range_start (eol_range_start); free (rp); |