<s>
The	O
C	B-Language
programming	I-Language
language	I-Language
has	O
a	O
set	O
of	O
functions	O
implementing	O
operations	O
on	O
strings	O
(	O
character	O
strings	O
and	O
byte	O
strings	O
)	O
in	O
its	O
standard	B-Language
library	I-Language
.	O
</s>
<s>
For	O
character	O
strings	O
,	O
the	O
standard	B-Language
library	I-Language
uses	O
the	O
convention	O
that	O
strings	O
are	O
null-terminated	B-Data_Structure
:	O
a	O
string	O
of	O
characters	O
is	O
represented	O
as	O
an	O
array	B-Data_Structure
of	O
elements	O
,	O
the	O
last	O
of	O
which	O
is	O
a	O
character	O
(	O
with	O
numeric	O
value	O
0	O
)	O
.	O
</s>
<s>
The	O
only	O
support	O
for	O
strings	O
in	O
the	O
programming	O
language	O
proper	O
is	O
that	O
the	O
compiler	O
translates	O
quoted	O
string	O
constants	O
into	O
null-terminated	B-Data_Structure
strings	I-Data_Structure
.	O
</s>
<s>
String	B-Language
literals	I-Language
(	O
"	O
text	O
"	O
in	O
the	O
C	B-Language
source	O
code	O
)	O
are	O
converted	O
to	O
arrays	O
during	O
compilation	O
.	O
</s>
<s>
The	O
result	O
is	O
an	O
array	B-Data_Structure
of	O
code	O
units	O
containing	O
all	O
the	O
characters	O
plus	O
a	O
trailing	O
zero	O
code	O
unit	O
.	O
</s>
<s>
A	O
string	B-Language
literal	I-Language
can	O
contain	O
the	O
zero	O
code	O
unit	O
(	O
one	O
way	O
is	O
to	O
put	O
\0	O
into	O
the	O
source	O
)	O
,	O
but	O
this	O
will	O
cause	O
the	O
string	O
to	O
end	O
at	O
that	O
point	O
.	O
</s>
<s>
The	O
rest	O
of	O
the	O
literal	O
will	O
be	O
placed	O
in	O
memory	O
(	O
with	O
another	O
zero	O
code	O
unit	O
added	O
to	O
the	O
end	O
)	O
but	O
it	O
is	O
impossible	O
to	O
know	O
those	O
code	O
units	O
were	O
translated	O
from	O
the	O
string	B-Language
literal	I-Language
,	O
therefore	O
such	O
source	O
code	O
is	O
not	O
a	O
string	B-Language
literal	I-Language
.	O
</s>
<s>
Consequently	O
,	O
a	O
byte	O
string	O
(	O
)	O
can	O
contain	O
non-NUL	O
characters	O
in	O
ASCII	B-Protocol
or	O
any	O
ASCII	B-Protocol
extension	I-Protocol
,	O
but	O
not	O
characters	O
in	O
encodings	O
such	O
as	O
UTF-16	O
(	O
even	O
though	O
a	O
16-bit	O
code	O
unit	O
might	O
be	O
nonzero	O
,	O
its	O
high	O
or	O
low	O
byte	O
might	O
be	O
zero	O
)	O
.	O
</s>
<s>
This	O
was	O
recognized	O
as	O
a	O
defect	O
in	O
the	O
standard	O
and	O
fixed	O
in	O
C++	O
.	O
)	O
</s>
<s>
C++11	O
and	O
C11	O
add	O
two	O
types	O
with	O
explicit	O
widths	O
and	O
.	O
</s>
<s>
UTF-8	O
and	O
Shift	O
JIS	O
are	O
often	O
used	O
in	O
C	B-Language
byte	O
strings	O
,	O
while	O
UTF-16	O
is	O
often	O
used	O
in	O
C	B-Language
wide	O
strings	O
when	O
wchar_t	O
is	O
16	O
bits	O
.	O
</s>
<s>
Since	O
C11	O
(	O
and	O
C++11	O
)	O
,	O
a	O
new	O
literal	O
syntax	O
is	O
available	O
that	O
guarantees	O
UTF-8	O
for	O
a	O
bytestring	O
literal	O
.	O
</s>
<s>
Since	O
C++20	B-Language
and	O
C23	B-Language
,	O
a	O
char8_t	O
type	O
was	O
added	O
that	O
is	O
meant	O
to	O
store	O
UTF-8	O
characters	O
and	O
the	O
types	O
of	O
u8	O
prefixed	O
character	O
and	O
string	B-Language
literals	I-Language
were	O
changed	O
to	O
char8_t	O
and	O
char8_t[]	O
respectively	O
.	O
</s>
<s>
Most	O
of	O
the	O
functions	O
that	O
operate	O
on	O
C	B-Language
strings	I-Language
are	O
declared	O
in	O
the	O
string.h	B-Language
header	O
(	O
cstring	B-Data_Structure
in	O
C++	O
)	O
,	O
while	O
functions	O
that	O
operate	O
on	O
C	B-Language
wide	O
strings	O
are	O
declared	O
in	O
the	O
wchar.h	B-Language
header	O
(	O
cwchar	B-Language
in	O
C++	O
)	O
.	O
</s>
<s>
Functions	O
declared	O
in	O
string.h	B-Language
are	O
extremely	O
popular	O
since	O
,	O
as	O
a	O
part	O
of	O
the	B-Language
C	I-Language
standard	I-Language
library	I-Language
,	O
they	O
are	O
guaranteed	O
to	O
work	O
on	O
any	O
platform	O
which	O
supports	O
C	B-Language
.	O
However	O
,	O
some	O
security	O
issues	O
exist	O
with	O
these	O
functions	O
,	O
such	O
as	O
potential	O
buffer	B-General_Concept
overflows	I-General_Concept
when	O
not	O
used	O
carefully	O
and	O
properly	O
,	O
causing	O
the	O
programmers	O
to	O
prefer	O
safer	O
and	O
possibly	O
less	O
portable	O
variants	O
,	O
out	O
of	O
which	O
some	O
popular	O
ones	O
are	O
listed	O
below	O
.	O
</s>
<s>
To	O
correct	O
this	O
,	O
some	O
have	O
been	O
separated	O
into	O
two	O
overloaded	B-Language
functions	I-Language
in	O
the	O
C++	O
version	O
of	O
the	O
standard	B-Language
library	I-Language
.	O
</s>
<s>
In	O
historical	O
documentation	O
the	O
term	O
"	O
character	O
"	O
was	O
often	O
used	O
instead	O
of	O
"	O
byte	O
"	O
for	O
C	B-Language
strings	I-Language
,	O
which	O
leads	O
many	O
to	O
believe	O
that	O
these	O
functions	O
somehow	O
do	O
not	O
work	O
for	O
UTF-8	O
.	O
</s>
<s>
The	O
BSD	B-Operating_System
documentation	O
has	O
been	O
fixed	O
to	O
make	O
this	O
clear	O
,	O
but	O
POSIX	O
,	O
Linux	B-Operating_System
,	O
and	O
Windows	O
documentation	O
still	O
uses	O
"	O
character	O
"	O
in	O
many	O
places	O
where	O
"	O
byte	O
"	O
or	O
"	O
wchar_t	O
"	O
is	O
the	O
correct	O
term	O
.	O
</s>
<s>
The	O
C	B-Language
standard	O
only	O
requires	O
that	O
be	O
wide	O
enough	O
to	O
hold	O
the	O
widest	O
character	O
set	O
among	O
the	O
supported	O
system	O
locales	B-Language
and	O
be	O
greater	O
or	O
equal	O
in	O
size	O
to	O
,	O
Integer	O
type	O
that	O
can	O
hold	O
any	O
value	O
of	O
a	O
wchar_t	O
as	O
well	O
as	O
the	O
value	O
of	O
the	O
macro	O
WEOF	O
.	O
</s>
<s>
The	B-Language
C	I-Language
standard	I-Language
library	I-Language
contains	O
several	O
functions	O
for	O
numeric	O
conversions	O
.	O
</s>
<s>
The	O
functions	O
that	O
deal	O
with	O
byte	O
strings	O
are	O
defined	O
in	O
the	O
header	O
(	O
header	O
in	O
C++	O
)	O
.	O
</s>
<s>
The	O
functions	O
that	O
deal	O
with	O
wide	O
strings	O
are	O
defined	O
in	O
the	O
header	O
(	O
header	O
in	O
C++	O
)	O
.	O
</s>
<s>
This	O
has	O
been	O
fixed	O
in	O
C23	B-Language
.	O
</s>
<s>
Name	O
Platform	O
Description	O
POSIX	O
,	O
BSD	B-Operating_System
Fills	O
a	O
buffer	O
with	O
zero	O
bytes	O
,	O
deprecated	O
by	O
SVID	B-Operating_System
,	O
POSIX	O
Part	O
of	O
the	O
C	B-Language
standard	O
since	O
C23	B-Language
,	O
copies	O
between	O
two	O
non-overlapping	O
memory	O
areas	O
,	O
stopping	O
when	O
a	O
given	O
byte	O
is	O
found	O
.	O
</s>
<s>
GNU	O
a	O
variant	O
of	O
returning	O
a	O
pointer	O
to	O
the	O
byte	O
following	O
the	O
last	O
written	O
byte	O
POSIX	O
,	O
BSD	B-Operating_System
case-insensitive	O
versions	O
of	O
Windows	O
a	O
variant	O
of	O
that	O
checks	O
the	O
destination	O
buffer	O
size	O
before	O
copying	O
Windows	O
a	O
variant	O
of	O
that	O
checks	O
the	O
destination	O
buffer	O
size	O
before	O
copying	O
POSIX	O
Part	O
of	O
the	O
C	B-Language
standard	O
since	O
C23	B-Language
,	O
allocates	O
and	O
duplicates	O
a	O
string	O
POSIX	O
1	O
,	O
GNU	O
a	O
variant	O
of	O
that	O
is	O
thread-safe	O
.	O
</s>
<s>
Windows	O
case-insensitive	O
versions	O
of	O
BSD	B-Operating_System
,	O
Solaris	B-Application
a	O
variant	O
of	O
that	O
truncates	O
the	O
result	O
to	O
fit	O
in	O
the	O
destination	O
buffer	O
BSD	B-Operating_System
,	O
Solaris	B-Application
a	O
variant	O
of	O
that	O
truncates	O
the	O
result	O
to	O
fit	O
in	O
the	O
destination	O
buffer	O
POSIX:2008	O
returns	O
string	O
representation	O
of	O
a	O
signal	B-Operating_System
code	I-Operating_System
.	O
</s>
<s>
POSIX	O
a	O
variant	O
of	O
that	O
is	O
thread-safe	O
Windows	O
Part	O
of	O
the	O
C	B-Language
standard	O
since	O
C23	B-Language
,	O
in	O
,	O
a	O
type	O
that	O
is	O
suitable	O
for	O
storing	O
UTF-8	O
characters	O
.	O
</s>
<s>
C99	B-Language
Part	O
of	O
the	O
C	B-Language
standard	O
since	O
C11	O
,	O
in	O
,	O
a	O
type	O
capable	O
of	O
holding	O
16	O
bits	O
even	O
if	O
is	O
another	O
size	O
.	O
</s>
<s>
C99	B-Language
Part	O
of	O
the	O
C	B-Language
standard	O
since	O
C11	O
,	O
in	O
,	O
a	O
type	O
capable	O
of	O
holding	O
32	O
bits	O
even	O
if	O
is	O
another	O
size	O
.	O
</s>
<s>
Despite	O
the	O
well-established	O
need	O
to	O
replace	O
strcat	O
and	O
strcpy	O
with	O
functions	O
that	O
do	O
not	O
allow	O
buffer	B-General_Concept
overflows	I-General_Concept
,	O
no	O
accepted	O
standard	O
has	O
arisen	O
.	O
</s>
<s>
This	O
is	O
partly	O
due	O
to	O
the	O
mistaken	O
belief	O
by	O
many	O
C	B-Language
programmers	O
that	O
strncat	O
and	O
strncpy	O
have	O
the	O
desired	O
behavior	O
;	O
however	O
,	O
neither	O
function	O
was	O
designed	O
for	O
this	O
(	O
they	O
were	O
intended	O
to	O
manipulate	O
null-padded	O
fixed-size	O
string	O
buffers	O
,	O
a	O
data	O
format	O
less	O
commonly	O
used	O
in	O
modern	O
software	O
)	O
,	O
and	O
the	O
behavior	O
and	O
arguments	O
are	O
non-intuitive	O
and	O
often	O
written	O
incorrectly	O
even	O
by	O
expert	O
programmers	O
.	O
</s>
<s>
The	O
most	O
popular	O
replacement	O
are	O
the	O
strlcat	O
and	O
strlcpy	O
functions	O
,	O
which	O
appeared	O
in	O
OpenBSD	B-Operating_System
2.4	O
in	O
December	O
,	O
1998	O
.	O
</s>
<s>
They	O
have	O
been	O
criticized	O
on	O
the	O
basis	O
of	O
allegedly	O
being	O
inefficient	O
,	O
encouraging	O
the	O
use	O
of	O
C	B-Language
strings	I-Language
(	O
instead	O
of	O
some	O
superior	O
alternative	O
form	O
of	O
string	O
)	O
,	O
and	O
hiding	O
other	O
potential	O
errors	O
.	O
</s>
<s>
Consequently	O
,	O
they	O
have	O
not	O
been	O
included	O
in	O
the	O
GNU	B-Language
C	I-Language
library	I-Language
(	O
used	O
by	O
software	O
on	O
Linux	B-Operating_System
)	O
,	O
although	O
they	O
are	O
implemented	O
in	O
the	O
C	B-Language
libraries	I-Language
for	O
OpenBSD	B-Operating_System
,	O
FreeBSD	B-Operating_System
,	O
NetBSD	B-Device
,	O
Solaris	B-Application
,	O
OS	B-Operating_System
X	I-Operating_System
,	O
and	O
QNX	B-Operating_System
,	O
as	O
well	O
as	O
in	O
alternative	O
C	B-Language
libraries	I-Language
for	O
Linux	B-Operating_System
,	O
such	O
as	O
,	O
introduced	O
in	O
2008	O
,	O
and	O
musl	B-Language
,	O
introduced	O
in	O
2011	O
.	O
</s>
<s>
The	O
lack	O
of	O
GNU	B-Language
C	I-Language
library	I-Language
support	O
has	O
not	O
stopped	O
various	O
software	O
authors	O
from	O
using	O
it	O
and	O
bundling	O
a	O
replacement	O
,	O
among	O
other	O
SDL	O
,	O
GLib	B-Language
,	O
ffmpeg	B-Library
,	O
rsync	B-Application
,	O
and	O
even	O
internally	O
in	O
the	O
Linux	B-Operating_System
kernel	I-Operating_System
.	O
</s>
<s>
Since	O
they	O
need	O
a	O
buffer	O
length	O
as	O
a	O
parameter	O
,	O
correct	O
setting	O
of	O
this	O
parameter	O
can	O
avoid	O
buffer	B-General_Concept
overflows	I-General_Concept
.	O
</s>
<s>
These	O
functions	O
attracted	O
considerable	O
criticism	O
because	O
initially	O
they	O
were	O
implemented	O
only	O
on	O
Windows	O
and	O
at	O
the	O
same	O
time	O
warning	O
messages	O
started	O
to	O
be	O
produced	O
by	O
Microsoft	B-Application
Visual	I-Application
C++	I-Application
suggesting	O
the	O
programmers	O
to	O
use	O
these	O
functions	O
instead	O
of	O
standard	O
ones	O
.	O
</s>
<s>
Although	O
open-source	O
implementations	O
of	O
these	O
functions	O
are	O
available	O
,	O
these	O
functions	O
are	O
not	O
present	O
in	O
common	O
Unix	O
C	B-Language
libraries	I-Language
.	O
</s>
<s>
Experience	O
with	O
these	O
functions	O
has	O
shown	O
significant	O
problems	O
with	O
their	O
adoption	O
and	O
errors	O
in	O
usage	O
,	O
so	O
the	O
removal	O
of	O
Annex	O
K	O
is	O
proposed	O
for	O
the	O
next	O
revision	O
of	O
the	O
C	B-Language
standard	O
.	O
</s>
