Need strnlen().

Daryl Clevenger dlc at a.sei.cmu.edu
Thu Nov 14 06:20:39 AEST 1985


One should never allow a character array to not have a null terminating byte.
Doing things like this should be automatic.  Besides, usually when the program
dumps core, one usually can find the problem readily.  Also, if I am not
mistaken, having character arrays that do not have terminating null bytes
will cause problems with many other funtions e.g printf().  printf() (or
maybe _doprint() I'm not sure which) will keep printing characters until they
hit that null byte, but they probably won't find it where it should be.
Unless I'm wrong, making sure strings are null terminated should be as
automatic as making sure that you aren't trying to use NULL pointers or
that malloc() returns a valid pointer.



More information about the Comp.lang.c mailing list