[Info-vax] C str calls
Stephen Hoffman
seaohveh at hoffmanlabs.invalid
Sat Aug 22 12:49:48 EDT 2015
FWIW, mentioned in another reply...
Existing C code with any of the not-length-limited <string.h> calls
should be reworked when updated, and new C code should avoid use of the
not-length-limited calls.
In particular, strlen should be replaced by strnlen, strcpy by strncpy
or potentially by memcpy, strcat by strncat, etc.
When specifying the length for the buffer, also always use the target
buffer length.
Where available, the BSD-derived strl string calls can be preferable to
the str calls and even to the strn calls, as the strl string calls are
intended to avoid various common buffer overruns.
In some of the more complex local code, use of the not-limited str
calls will trigger compilation warnings.
String descriptors — arguably, these are a primitive and limited form
of an object — do have some advantages here, yes. But it's still
possible for even descriptor-based programs to trash the heap or
otherwise get into trouble, usually when mixed with calls and code that
doesn't fully support descriptors, such as system services and various
itemlists.
--
Pure Personal Opinion | HoffmanLabs LLC
More information about the Info-vax
mailing list