Some static code analyzer tools are suggesting that all strcat usage should be replaced with strncat for safety purpose?
In a program, if we know clearly the size of
They don't do the same thing so they can't be substituted for one another. Both have different data models.
strcat
is a null
terminated string for which you (as the programmer) guarantee that it has enough space.strncat
is a sequence
of char
that is either terminated
at the length you are indicating or
by a null termination if it is
supposed to be shorter than that
length.So the use of these functions just depends on the assumptions that you may (or want to) do about your data.