diff options
author | Paul Eggert <eggert@cs.ucla.edu> | 2010-08-03 10:24:11 -0700 |
---|---|---|
committer | Paul Eggert <eggert@cs.ucla.edu> | 2010-08-03 10:25:47 -0700 |
commit | a2cebacf9748d60d6763f8ada68a10958a9cbda2 (patch) | |
tree | 4c911b6105aa863c8a9073d262fb3796f8295e7f /src | |
parent | 94615d2acfdccbbeb8eb6f8931d0e252b05e1484 (diff) | |
download | coreutils-a2cebacf9748d60d6763f8ada68a10958a9cbda2.tar.xz |
sort: fix bug in --debug when \0 is followed by \t
* src/sort.c (debug_width): New function, which does not stop
counting tabs at \0, and also invokes mbsnwidth. Stamp out strnlen!
(count_tabs): Remove.
(debug_key): Use debug_width instead of mbsnwidth and count_tabs.
* tests/misc/sort-debug-keys: Check that \0 and \t intermix.
Diffstat (limited to 'src')
-rw-r--r-- | src/sort.c | 28 |
1 files changed, 9 insertions, 19 deletions
diff --git a/src/sort.c b/src/sort.c index e02e547d2..1df711da7 100644 --- a/src/sort.c +++ b/src/sort.c @@ -2102,23 +2102,17 @@ compare_version (char *restrict texta, size_t lena, return diff; } -/* For debug mode, count tabs in the passed string - so we can adjust the widths returned by mbswidth. +/* Return the printable width of the block of memory starting at + TEXT and ending just before LIM, counting each tab as one byte. FIXME: Should we generally be counting non printable chars? */ static size_t -count_tabs (char const *text, size_t len) +debug_width (char const *text, char const *lim) { - size_t tabs = 0; - size_t tlen = strnlen (text, len); - - while (tlen--) - { - if (*text++ == '\t') - tabs++; - } - - return tabs; + size_t width = mbsnwidth (text, lim - text, 0); + while (text < lim) + width += (*text++ == '\t'); + return width; } /* For debug mode, "underline" a key at the @@ -2161,12 +2155,8 @@ debug_key (char const *sline, char const *sfield, char const *efield, } } - size_t offset = mbsnwidth (sline, sfield - sline, 0) + (sa - sfield); - offset += count_tabs (sline, sfield - sline); - - size_t width = mbsnwidth (sa, flen, 0); - width += count_tabs (sa, flen); - + size_t offset = debug_width (sline, sfield) + (sa - sfield); + size_t width = debug_width (sa, sa + flen); mark_key (offset, width); } |