summaryrefslogtreecommitdiff
path: root/src/sort.c
diff options
context:
space:
mode:
authorPaul R. Eggert <eggert@cs.ucla.edu>2010-07-15 16:24:03 -0700
committerPaul Eggert <eggert@cs.ucla.edu>2010-07-15 16:24:38 -0700
commitc580983f70cbc567e68ad2fbadca92341646b018 (patch)
treee7408e2138c5a1f9bf92264f6a0294c849ac9e90 /src/sort.c
parentaadc67dfdb47f28bb8d1fa5e0fe0f52e2a8c51bf (diff)
downloadcoreutils-c580983f70cbc567e68ad2fbadca92341646b018.tar.xz
sort: fix a bug with sort -u and xmemcoll0, and tune keycompare
* src/sort.c (keycompare): Use xmemcoll0, as it avoids a couple of stores. (write_bytes): Leave the buffer the way we found it, as it might be used again for a later comparison, if -u is used.
Diffstat (limited to 'src/sort.c')
-rw-r--r--src/sort.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/src/sort.c b/src/sort.c
index 7d318788c..960df747a 100644
--- a/src/sort.c
+++ b/src/sort.c
@@ -2497,7 +2497,9 @@ keycompare (const struct line *a, const struct line *b, bool show_debug)
}
}
- diff = xmemcoll (copy_a, new_len_a, copy_b, new_len_b);
+ copy_a[new_len_a++] = '\0';
+ copy_b[new_len_b++] = '\0';
+ diff = xmemcoll0 (copy_a, new_len_a, copy_b, new_len_b);
if (sizeof buf < size)
free (copy_a);
@@ -2664,13 +2666,11 @@ write_bytes (struct line const *line, FILE *fp, char const *output_file)
{
char *buf = line->text;
size_t n_bytes = line->length;
-
- *(buf + n_bytes - 1) = eolchar;
+ char *ebuf = buf + n_bytes;
/* Convert TABs to '>' and \0 to \n when -z specified. */
if (debug && fp == stdout)
{
- char const *ebuf = buf + n_bytes;
char const *c = buf;
while (c < ebuf)
@@ -2678,7 +2678,7 @@ write_bytes (struct line const *line, FILE *fp, char const *output_file)
char wc = *c++;
if (wc == '\t')
wc = '>';
- else if (wc == 0 && eolchar == 0)
+ else if (c == ebuf)
wc = '\n';
if (fputc (wc, fp) == EOF)
die (_("write failed"), output_file);
@@ -2688,8 +2688,10 @@ write_bytes (struct line const *line, FILE *fp, char const *output_file)
}
else
{
+ ebuf[-1] = eolchar;
if (fwrite (buf, 1, n_bytes, fp) != n_bytes)
die (_("write failed"), output_file);
+ ebuf[-1] = '\0';
}
}