mailing list of musl libc
 help / color / mirror / code / Atom feed
* src/string/strstr.c, src/string/wcsstr.c: wrong estimates for MIN(l,63)?
@ 2014-03-21 14:07 Yves Bastide
  2014-03-21 16:48 ` Rich Felker
  0 siblings, 1 reply; 5+ messages in thread
From: Yves Bastide @ 2014-03-21 14:07 UTC (permalink / raw)
  To: musl

Hi,

twoway_strstr and twoway_wcsstr seem to contain a bogus estimation:

/* Fast estimate for MIN(l,63) */
size_t grow = l | 63;

"grow" is thus always at least 63...

Regards,

Yves


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: src/string/strstr.c, src/string/wcsstr.c: wrong estimates for MIN(l,63)?
  2014-03-21 14:07 src/string/strstr.c, src/string/wcsstr.c: wrong estimates for MIN(l,63)? Yves Bastide
@ 2014-03-21 16:48 ` Rich Felker
  2014-03-21 17:07   ` Szabolcs Nagy
  0 siblings, 1 reply; 5+ messages in thread
From: Rich Felker @ 2014-03-21 16:48 UTC (permalink / raw)
  To: musl

On Fri, Mar 21, 2014 at 03:07:22PM +0100, Yves Bastide wrote:
> Hi,
> 
> twoway_strstr and twoway_wcsstr seem to contain a bogus estimation:
> 
> /* Fast estimate for MIN(l,63) */
> size_t grow = l | 63;
> 
> "grow" is thus always at least 63...

If you look at how grow is used on the very next line, this should
make sense.

Rich


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: src/string/strstr.c, src/string/wcsstr.c: wrong estimates for MIN(l,63)?
  2014-03-21 16:48 ` Rich Felker
@ 2014-03-21 17:07   ` Szabolcs Nagy
  2014-03-21 17:44     ` Rich Felker
  0 siblings, 1 reply; 5+ messages in thread
From: Szabolcs Nagy @ 2014-03-21 17:07 UTC (permalink / raw)
  To: musl

* Rich Felker <dalias@aerifal.cx> [2014-03-21 12:48:17 -0400]:
> On Fri, Mar 21, 2014 at 03:07:22PM +0100, Yves Bastide wrote:
> > /* Fast estimate for MIN(l,63) */
> > size_t grow = l | 63;
> > 
> > "grow" is thus always at least 63...
> 
> If you look at how grow is used on the very next line, this should
> make sense.

the comment is wrong though
z grows by at least max(63,l) unless end-of-string is reached


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: src/string/strstr.c, src/string/wcsstr.c: wrong estimates for MIN(l,63)?
  2014-03-21 17:07   ` Szabolcs Nagy
@ 2014-03-21 17:44     ` Rich Felker
  2014-03-21 18:10       ` Yves Bastide
  0 siblings, 1 reply; 5+ messages in thread
From: Rich Felker @ 2014-03-21 17:44 UTC (permalink / raw)
  To: musl

On Fri, Mar 21, 2014 at 06:07:45PM +0100, Szabolcs Nagy wrote:
> * Rich Felker <dalias@aerifal.cx> [2014-03-21 12:48:17 -0400]:
> > On Fri, Mar 21, 2014 at 03:07:22PM +0100, Yves Bastide wrote:
> > > /* Fast estimate for MIN(l,63) */
> > > size_t grow = l | 63;
> > > 
> > > "grow" is thus always at least 63...
> > 
> > If you look at how grow is used on the very next line, this should
> > make sense.
> 
> the comment is wrong though
> z grows by at least max(63,l) unless end-of-string is reached

Yes, (l|63) is >= both l and 63, so it should read MAX, not MIN. The
idea is that it's useless to grow by less than l, but it's inefficient
to grow by less than some fixed threshold even if the needle is tiny.

Rich


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: src/string/strstr.c, src/string/wcsstr.c: wrong estimates for MIN(l,63)?
  2014-03-21 17:44     ` Rich Felker
@ 2014-03-21 18:10       ` Yves Bastide
  0 siblings, 0 replies; 5+ messages in thread
From: Yves Bastide @ 2014-03-21 18:10 UTC (permalink / raw)
  To: musl

2014-03-21 18:44 GMT+01:00 Rich Felker <dalias@aerifal.cx>:
> On Fri, Mar 21, 2014 at 06:07:45PM +0100, Szabolcs Nagy wrote:
>> * Rich Felker <dalias@aerifal.cx> [2014-03-21 12:48:17 -0400]:
>> > On Fri, Mar 21, 2014 at 03:07:22PM +0100, Yves Bastide wrote:
>> > > /* Fast estimate for MIN(l,63) */
>> > > size_t grow = l | 63;
>> > >
>> > > "grow" is thus always at least 63...
>> >
>> > If you look at how grow is used on the very next line, this should
>> > make sense.
>>
>> the comment is wrong though
>> z grows by at least max(63,l) unless end-of-string is reached
>
> Yes, (l|63) is >= both l and 63, so it should read MAX, not MIN. The
> idea is that it's useless to grow by less than l, but it's inefficient
> to grow by less than some fixed threshold even if the needle is tiny.
>
> Rich

OK, understood.

Thanks!

yves


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2014-03-21 18:10 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-03-21 14:07 src/string/strstr.c, src/string/wcsstr.c: wrong estimates for MIN(l,63)? Yves Bastide
2014-03-21 16:48 ` Rich Felker
2014-03-21 17:07   ` Szabolcs Nagy
2014-03-21 17:44     ` Rich Felker
2014-03-21 18:10       ` Yves Bastide

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).