[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [coreutils] [PATCH 1/2] sort: avoid unnecessary use of sprintf
From: |
Jim Meyering |
Subject: |
Re: [coreutils] [PATCH 1/2] sort: avoid unnecessary use of sprintf |
Date: |
Tue, 08 Jun 2010 13:13:17 +0200 |
Pádraig Brady wrote:
> On 08/06/10 10:42, Jim Meyering wrote:
>> This first patch removes uses of sprintf in favor of
>> umaxtostr and stpcpy.
>
> A little less standard, and we don't really care
> about performance in --debug, but fair enough.
It was partly on principle: keep things tight/minimal,
since there were no other uses of sprintf.
Also, using sprintf at all raises warning flags,
since it's so easy to use incorrectly...
> Note I think you can remove the uintmax_t case from
> the umaxtostr parameters.
Thanks. I've removed those two casts.
>> It also adjusts some uses of INT_BUFSIZE_BOUND to use
>> a variable name rather than a type.
>
> Good one.
>> Subject: [PATCH 2/2] maint: adjust INT_BUFSIZE_BOUND usage for
>> maintainability
>>
>> * src/tail.c (xlseek): Give INT_BUFSIZE_BOUND a variable name,
>> not a type name.
>> * src/ls.c (gobble_file, format_user_or_group_width): Likewise.
>> * src/head.c (elide_tail_bytes_pipe): Likewise.
>> (elide_tail_lines_seekable, main): Likewise.
>
> There may be others?
> grep "BOUND ([ilus]" *.c
Yes, definitely.
I didn't finish the job.
Several uses in ls.c looked like changing would not benefit.
Same for these two in test.c, since there is no variable per se:
{
char lbuf[INT_BUFSIZE_BOUND (uintmax_t)];
char rbuf[INT_BUFSIZE_BOUND (uintmax_t)];
char const *l = (l_is_l
? umaxtostr (strlen (argv[op - 1]), lbuf)
: find_int (argv[op - 1]));
char const *r = (r_is_l
? umaxtostr (strlen (argv[op + 2]), rbuf)
: find_int (argv[op + 1]));
But I haven't looked at many of the remaining cases.
If you feel like it, you're welcome to finish.