This is the mail archive of the systemtap@sourceware.org mailing list for the systemtap project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Fix tokenize function and test.


On 06/13/2009 05:33 AM, Przemyslaw Pawelczyk wrote:
> Previous implementation was error-prone, because allowed returning empty
> tokens (mimiced strsep()), which is fine if there is a NULL semantic.
> Unfortunately SystemTap doesn't provide it in scripts and has only blank
> string (""), therefore testing against it was misleading.
> The solution is to return only non-empty tokens (mimic strtok()).
> 
> * tapset/string.stp: Fix tokenize.
> * testsuite/systemtap.string/tokenize.stp: Improve and add case with
>   more than one delimiter in the delim string.
> * stapfuncs.3stap.in: Update tokenize description.
> * doc/langref.tex: Ditto.
[...]

> -	token = strsep(&str_start, THIS->delim);
> +	while ((token = strsep(&str_start, THIS->delim)) && !token[0])
> +		;

do-while would be cleaner, please.

>  	if (token)
> -		strncpy (THIS->__retvalue, token, MAXSTRINGLEN);
> +		strncpy(THIS->__retvalue, token, (str_start ? str_start : str_end + 1) - token);
>  %}

Why do you need the explicit length computation?  There will always be a
NUL there anyway, right?  I tried reverting this part, and the tests
still pass, so I don't see what this is for.

Also, while we're at it, strlcpy would be preferred for better
termination semantics (guaranteed NUL and no extra NUL padding).


Josh


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]