[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [coreutils] [PATCH] uniq: don't continue field processing after end
From: |
Jim Meyering |
Subject: |
Re: [coreutils] [PATCH] uniq: don't continue field processing after end of line |
Date: |
Tue, 18 Jan 2011 09:56:33 +0100 |
Jim Meyering wrote:
> Pádraig Brady wrote:
>
>> On 16/01/11 23:53, Sami Kerola wrote:
>>> Hi,
>>>
>>> I notice uniq -f 'insane_large_number' will make process to be busy
>>> long time without good reason. Attached patch should fix this symptom.
>>
>> I'd slightly amend that to the following,
>> to match the other limit checks in the function.
>>
>> diff --git a/src/uniq.c b/src/uniq.c
>> index 7bdbc4f..9c7e37c 100644
>> --- a/src/uniq.c
>> +++ b/src/uniq.c
>> @@ -214,7 +214,7 @@ find_field (struct linebuffer const *line)
>> size_t size = line->length - 1;
>> size_t i = 0;
>>
>> - for (count = 0; count < skip_fields; count++)
>> + for (count = 0; count < skip_fields && i < size; count++)
>> {
>> while (i < size && isblank (to_uchar (lp[i])))
>
> Thank you!
> I've also adjusted NEWS.
> Here's your adjusted patch, followed by another to add a test
> to exercise the bug/fix:
>
> Subject: [PATCH] uniq: don't continue field processing after end of line
>
> * NEWS (Bug fixes): Mention it.
> * src/uniq.c (find_field): Stop processing loop when end of line
> is reached. Before this fix, 'uniq -f 10000000000 /etc/passwd'
> would run for a very long time.
> ---
> NEWS | 2 ++
> src/uniq.c | 2 +-
> 2 files changed, 3 insertions(+), 1 deletions(-)
>
> diff --git a/NEWS b/NEWS
> index 9ccad63..3ec35c7 100644
> --- a/NEWS
> +++ b/NEWS
> @@ -13,6 +13,8 @@ GNU coreutils NEWS -*-
> outline -*-
> rm -f no longer fails for EINVAL or EILSEQ on file systems that
> reject file names invalid for that file system.
>
> + uniq -f NUM no longer tries to process fields after end of line.
I pushed that, then realized that we hadn't noted the origin
of the bug:
>From 34ece0b0a1e19f1faef8edfe3d59c5a2f5209369 Mon Sep 17 00:00:00 2001
From: Jim Meyering <address@hidden>
Date: Tue, 18 Jan 2011 09:45:00 +0100
Subject: [PATCH] doc: update NEWS
* NEWS: Note when the uniq bug was introduced.
It was mine, commit 1d9b3de9, "uniq: remove redundant test".
---
NEWS | 1 +
1 files changed, 1 insertions(+), 0 deletions(-)
diff --git a/NEWS b/NEWS
index 3ec35c7..e420cd9 100644
--- a/NEWS
+++ b/NEWS
@@ -14,6 +14,7 @@ GNU coreutils NEWS -*-
outline -*-
reject file names invalid for that file system.
uniq -f NUM no longer tries to process fields after end of line.
+ [bug introduced in coreutils-7.0]
* Noteworthy changes in release 8.9 (2011-01-04) [stable]
--
1.7.3.5