From: Jim Meyering Date: Tue, 22 Jul 2003 13:00:45 +0000 (+0000) Subject: (set_fields): Mark all selected indices before trying to X-Git-Tag: v5.0.90~157 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3fe298f13f3665b2f1a083161928163c3848bfc8;p=thirdparty%2Fcoreutils.git (set_fields): Mark all selected indices before trying to determine range endpoints. --- diff --git a/src/cut.c b/src/cut.c index 90190aee07..cb3b7c57de 100644 --- a/src/cut.c +++ b/src/cut.c @@ -452,29 +452,34 @@ set_fields (const char *fieldstr) /* Set the array entries corresponding to integers in the ranges of RP. */ for (i = 0; i < n_rp; i++) { - unsigned int j = rp[i].lo; + unsigned int j; + for (j = rp[i].lo; j <= rp[i].hi; j++) + { + printable_field[j] = 1; + } + } - /* Mark the first position of each field or range with a sentinel, - but not if it's already part of another range. */ - if (j <= rp[i].hi && ! printable_field[j]) + if (output_delimiter_specified) + { + /* Record the range-start indices. */ + for (i = 0; i < n_rp; i++) { - if (output_delimiter_specified) + unsigned int j = rp[i].lo; + for (j = rp[i].lo; j <= rp[i].hi; j++) { - /* Remember that `j' is a range-start index. */ - void *ent_from_table = hash_insert (range_start_ht, (void*) j); - if (ent_from_table == NULL) + if (0 < j && printable_field[j] && !printable_field[j - 1]) { - /* Insertion failed due to lack of memory. */ - xalloc_die (); + /* Remember that `j' is a range-start index. */ + void *ent_from_table = hash_insert (range_start_ht, + (void*) j); + if (ent_from_table == NULL) + { + /* Insertion failed due to lack of memory. */ + xalloc_die (); + } + assert ((unsigned int) ent_from_table == j); } - assert ((unsigned int) ent_from_table == j); } - printable_field[j] = 1; - } - - for (++j; j <= rp[i].hi; j++) - { - printable_field[j] = 1; } }