When prefixes such as struct, union, etc. are compared with the current type (e.g. struct foo), a comparison is made with the prefix. The code currently assumes that every type is a valid C type with a prefix, however at times, garbage ends up in this function causing an unpredictable crash with DTrace due to the isspace(*p) call or subsequent calls. An example that I've seen of this is the letter 's' being passed in, comparing true with struct as the comparison size was (q - p) == 1, but then we increment p with the length of "struct", resulting in an out of bounds read. This diff simply adds some robustness checks to the surrounding code to prevent this from happening and causing weird behaviour.
Sorry, I had been focusing on the other change. Could you explain why this part is needed? I'm having trouble seeing how q or p can end up being NULL.
You're right. I've updated the diff to reflect it. I think it was left over from debugging when I thought my code had caused a memory corruption :-).