lkml.org 
[lkml]   [2001]   [May]   [3]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
SubjectRe: [PATCH] strtok -> strsep (The Easy Cases)
Date
In message <01050120580701.01713@golmepha> you write:
> Hello,
>
> the patch at the bottom does the bulk job of strtok replacement. It's a
> very boring patch, containing easy cases, only. It became a bit big, too,
> but I trust you can digest it nevertheless. It's made against kernel
> version 2.4.4.

There are two cases where the substitution is problematic:

Array:
char tmparray[500];
strcpy(tmparray, str);

/* for (p = strtok(tmparray, "n"); p; p = strtok(NULL, "n")) { */
while ((p = strsep(&tmparray, ","))) {

This is clearly wrong, and invokes a compiler warning. &tmparray ==
tmparray (a cute C oddity I've never really liked). You are blowing
away the first few characters in tmparray, and your parser won't work
properly.

Dynamic:

char *tmp = strdup(str);

/* for (p = strtok(tmp, "n"); p; p = strtok(NULL, "n")) { */
while ((p = strsep(&tmp, ","))) {
...
}

kfree(tmp);

Here, tmp has changed in the strsep implementation, and kfree will do
bad things.

There is a real reason to avoid strtok, and that is SMP and multple
threads calling it at once (that said, I don't know of a problem yet).
But this patch is a step backwards.

Rusty.
--
Premature optmztion is rt of all evl. --DK
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2005-03-22 12:52    [W:0.059 / U:2.044 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site