name resolve order

Jeremy Allison jallison at whistle.com
Tue Mar 17 00:47:23 GMT 1998


Andrew Tridgell wrote:
> 
> You have code like this:
> 
>   for (p=strtok(lp_name_resolve_order(),LIST_SEP); p; p = strtok(NULL,LIST_SEP)) {
>      /* look at p and decide what to do */
>   }
> 
> that will work most of the time, but may sometimes mysteriously fail!
> 
> The problem is the use of strtok() with a lp_* function that returns a
> string. The lp_* string functions put their result into a circular
> list of string buffers. That means you can change them, but you had
> better not be still using the string when you loop around in the
> circular list and hit the same one again.
> 

Thanks Andrew - I cut and pasted from the wrong bit of code ( I
cut and pasted from lp_add_auto_services in loadparm.c :-).


> The other minor bug is the use of strtok() in a non-leaf
> routine. strtok() uses static data an thus you can't call one strtok
> inside another without corruption. That's why we have the
> next_token() function in Samba, it doesn't use any static data.
> 
> Sorry to be so picky, but I thought it was worth explaining :-)
> 

No - that's brilliant. I'm really glad you're as picky
as you are. I'm cvs committing a changed version as I
type :-).

Cheers & thanks,

Jeremy.

-- 
--------------------------------------------------------
Buying an operating system without source is like buying
a self-assembly Space Shuttle with no instructions.
--------------------------------------------------------


More information about the samba-technical mailing list