You need to swap the tests: in C the tests are executed from left to right, and lazily (if at any point the result is known, further test are not executed).  So, if you check first `doc->file_type->extension != NULL` and then `doc->file_type != NULL`, the second test is useless since if `doc->file_type` was actually `NULL` the first test accessing a field of it would have crashed the program already.  So, just swap those tests :)