[PATCH] fix last corner case in strrstr.c

Denys Vlasenko vda.linux at googlemail.com
Wed Jun 18 19:52:37 UTC 2008


On Tuesday 17 June 2008 21:38, Tito wrote:
> this patch fixes this with no size increase:
> 
>  ./test
> 'baaabaaab'  vs. 'aaa'       : PASSED
> 'baaabaaaab' vs. 'aaa'       : PASSED
> 'baaabaab'   vs. 'aaa'       : PASSED
> 'aaa'        vs. 'aaa'       : PASSED
> 'aaa'        vs. 'a'         : PASSED
> 'aaa'        vs. 'bbb'       : PASSED
> 'a'          vs. 'aaa'       : PASSED
> 'aaa'        vs. ''          : PASSED
> ''           vs. 'aaa'       : PASSED
> ''           vs. ''          : PASSED
> 
> ./scripts/bloat-o-meter busybox_old busybox_unstripped
> function                                             old     new   delta
> ------------------------------------------------------------------------------
> (add/remove: 0/0 grow/shrink: 0/0 up/down: 0/0)                 Total: 0 bytes
> 
> Function is changed to:
> 
> char *strrstr(const char *haystack, const char *needle)
> {
> 	char *r = NULL;
> 	
> 	do {
> 		char *p = strstr(haystack, needle);
> 		if (p)
> 			r = p;
> 	} while (*haystack++);
> 	return r;
> }
> 
> The contra is that it is probably a little more cpu intensive :)

I'm sorry but cubic running time is a bit extreme to my tastes.
Especially that quadratic time version is just 2 bytes bigger.
--
vda



More information about the busybox mailing list