NULL pointer problem on SUN

Doug Gwyn gwyn at smoke.brl.mil
Sat Nov 10 19:23:44 AEST 1990


In article <1255 at digi.lonestar.org> theruska at digi.lonestar.org (Thomas Heruska) writes:
>I am having trouble using the function strtok on a SUN.  The function
>works perfectly on an HP and APOLLO system, so I am convinced that it is   
>a specific SUN problem.  

No, it's incorrect code on your part.

>   strcpy(token,strtok(mesg," \0"));    /* crashes here - should place
>                                              a NULL pointer in token   */

strcpy() requires valid source and destination pointer arguments.
A null pointer doesn't point anywhere.  Therefore it cannot be used
to fetch a 0-char-terminated array of bytes from the source location.

On systems where this APPEARS to work, it is only because on those
systems there happens to be something innocuous (probably starting
with a 0 byte value) at virtual address 0, and when strcpy() tries
to use the pointer you supplied to it, it looks just like address 0.

You should fix the code.  Null pointers don't point anywhere.



More information about the Comp.lang.c mailing list