[LEDE-DEV] [PATCH] libubox: replace strtok with strsep
Felix Fietkau
nbd at nbd.name
Fri Dec 16 02:10:53 PST 2016
On 2016-12-16 10:58, John Crispin wrote:
>
>
> On 14/12/2016 06:43, Rosen Penev wrote:
>> strsep is re-entrant whereas strtok not necessarily so.
>>
>> Signed-off by: Rosen Penev <rosenp at gmail.com>
>> ---
>> ulog.c | 4 ++--
>> 1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/ulog.c b/ulog.c
>> index 296605d..985d366 100644
>> --- a/ulog.c
>> +++ b/ulog.c
>> @@ -39,8 +39,8 @@ static const char *ulog_default_ident(void)
>> if ((self = fopen("/proc/self/status", "r")) != NULL) {
>> while (fgets(line, sizeof(line), self)) {
>> if (!strncmp(line, "Name:", 5)) {
>> - strtok(line, "\t\n");
>> - p = strtok(NULL, "\t\n");
>> + strsep(&line, "\t\n");
>> + p = strsep(&line, "\t\n");
>
> Hi,
>
> i agree that using strsep() is a nice api however i fail to see why the
> original code would fail. according to the man page it is re-entrant,
> specially if called as done here. can you elaborate a bit why you think
> it is not re-entrant ?
If the caller of ulog() is using strtok between ulog calls, internal use
of strtok can break it. I think this change is worth merging.
- Felix
More information about the Lede-dev
mailing list