This is the mail archive of the
systemtap@sourceware.org
mailing list for the systemtap project.
Re: [PATCH] Fix tokenize function.
- From: Przemysław Pawełczyk <przemyslaw at pawelczyk dot it>
- To: systemtap at sourceware dot org
- Date: Sat, 13 Jun 2009 13:40:18 +0200
- Subject: Re: [PATCH] Fix tokenize function.
- References: <1244863762.20494.8055@debian>
On Sat, Jun 13, 2009 at 05:13, Przemyslaw
Pawelczyk<przemyslaw@pawelczyk.it> 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()).
testsuite/systemtap.string/tokenize.exp turned out to be bogus,
because (for previous implementation of tokenize) blank textstr4
enabled further tokenization of textstr3, that should be already done.
In second version of the patch I'll fix also the test case. Simplified
example:
stap -e 'global s[2]; probe begin { s[1] = "before,,after"; s[2] = "";
foreach (i in s) { println(i); tok = tokenize(s[i], ","); while (tok
!= "") { println(tok); tok = tokenize("", ","); }}; exit(); }'
Result from previous implementation:
1
before
2
after
Result from my implementation:
1
before
after
2
> It was also unsafe, because NUL-termination wasn't guaranteed in the
> passed string, but this is crucial for proper strsep() working.
I unknowingly lied here, sorry. I'll remove that part in the second version.
Regards.
--
Przemysław Pawełczyk