Skip to content

strtok(NULL, ...) causes an unwanted warning  #348

@AlvajoyAsante

Description

@AlvajoyAsante

When running the following code using char *strtok(char *str, const char *delim):

int main (void) {
   char str[12] = "Hello World";
   char *token;

   token = strtok(str, " ");
   token = strtok(NULL, " ");
   
   return(0);
}

It gives an unwanted error stating:

warning: null passed to a callee that requires a non-null argument [-Wnonnull] 
 token = strtok(NULL, " ");
                ~~~~     ^

The issue is that strtok should be able to run a second iteration with a NULL as it's char *str without giving me a warning.

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions