This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
strtok behaviour when uninitialized
- From: Salil Kapur <salilkapur93 at gmail dot com>
- To: libc-alpha at sourceware dot org
- Date: Sun, 11 Feb 2018 13:19:54 -0500
- Subject: strtok behaviour when uninitialized
- Authentication-results: sourceware.org; auth=none
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