strtok behaviour when uninitialized

Salil Kapur salilkapur93@gmail.com
Sun Feb 11 18:53:00 GMT 2018


All,

When using strtok for the first time without initializing
it throws a segfault. Following code can reproduce the error

int main() {
    char* str = strtok(NULL, " ");
    return 1;
}

I am aware that this is not the correct way of using strtok. First
call should always pass a non NULL string. Before glibc 2.23 strtok
used to return a NULL for the above code. Would it make sense to
add a NULL check and not let strtok throw a segfault?

-Salil



More information about the Libc-alpha mailing list