@@ -34,28 +34,29 @@ int ksprintf(kstring_t *s, const char *fmt, ...)
34
34
return l ;
35
35
}
36
36
37
- char * kstrtok (const char * str , const char * sep , ks_tokaux_t * aux )
37
+ char * kstrtok (const char * str , const char * sep_in , ks_tokaux_t * aux )
38
38
{
39
- const char * p , * start ;
39
+ const unsigned char * p , * start , * sep = ( unsigned char * ) sep_in ;
40
40
if (sep ) { // set up the table
41
41
if (str == 0 && aux -> finished ) return 0 ; // no need to set up if we have finished
42
42
aux -> finished = 0 ;
43
- if (sep [1 ]) {
43
+ if (sep [0 ] && sep [ 1 ]) {
44
44
aux -> sep = -1 ;
45
45
aux -> tab [0 ] = aux -> tab [1 ] = aux -> tab [2 ] = aux -> tab [3 ] = 0 ;
46
46
for (p = sep ; * p ; ++ p ) aux -> tab [* p >>6 ] |= 1ull <<(* p & 0x3f );
47
47
} else aux -> sep = sep [0 ];
48
48
}
49
49
if (aux -> finished ) return 0 ;
50
- else if (str ) aux -> p = str - 1 , aux -> finished = 0 ;
50
+ else if (str ) start = (unsigned char * ) str , aux -> finished = 0 ;
51
+ else start = (unsigned char * ) aux -> p + 1 ;
51
52
if (aux -> sep < 0 ) {
52
- for (p = start = aux -> p + 1 ; * p ; ++ p )
53
+ for (p = start ; * p ; ++ p )
53
54
if (aux -> tab [* p >>6 ]>>(* p & 0x3f )& 1 ) break ;
54
55
} else {
55
- for (p = start = aux -> p + 1 ; * p ; ++ p )
56
+ for (p = start ; * p ; ++ p )
56
57
if (* p == aux -> sep ) break ;
57
58
}
58
- aux -> p = p ; // end of token
59
+ aux -> p = ( const char * ) p ; // end of token
59
60
if (* p == 0 ) aux -> finished = 1 ; // no more tokens
60
61
return (char * )start ;
61
62
}
0 commit comments