Home

NULtermination

NUL termination is a convention for representing text strings in memory by placing a null character at the end. The terminator, known as the NUL or null byte, has the value zero in ASCII. In this scheme a string consists of a sequence of characters followed by a trailing zero that signals the end to processing routines.

In languages and environments that use NUL-terminated strings, such as C, string length is determined by scanning

Problems arise if the terminating NUL is overwritten or missing, which can cause buffer overflows, crashes,

Alternatives include length-prefixed or bounded strings, and languages that track length separately (for example, C++'s std::string).

from
the
start
until
the
first
NUL.
Functions
like
strlen,
strcat,
and
strcpy
rely
on
the
terminator
to
delimit
the
string.
This
design
avoids
storing
a
length
field
but
requires
careful
management
to
preserve
the
terminating
character.
or
security
vulnerabilities.
Improper
handling
of
user
input
or
mixing
binary
data
with
text
can
exacerbate
risks.
Furthermore,
strings
containing
a
null
character
within
the
data
cannot
be
represented
directly
in
a
NUL-terminated
model.
Some
C
libraries
adopt
safer
routines
that
enforce
bounds,
such
as
snprintf
or
strlcpy
when
available.
NUL
termination
remains
a
foundational
concept
in
C
and
in
system
interfaces
that
require
C
compatibility,
even
as
newer
abstractions
lessen
reliance
on
it.