Strcpy

A C standard library function: `strcpy` is used to copy non-overlapping, null-terminated strings

Strncpy

A C standard library function: strncpy is used to copy a maximum of n characters of non-overlapping, fixed-width or null-terminated strings

Better things strlcpy

Quality Example
Better

"Strcpy could be better replaced by strncpy which does some bound checking"

from question "Operator= overloading in C++"

"Using strncpy 3 is better than strcpy 3 but things like strlcpy 3 are better still"

from question "Why is strncpy insecure?"

Actually better

"I.e strncpy is actually better than the simpler strcpy if you are willing to improve the code"

from question "Check if a string exists in an array, if not then add it to the array in C"

Unsafe cousins strcpy_s

Quality Example
Not safer

"Strncpy is not safer than strcpy it just trades one type of bugs with another"

from question "Why should you use strncpy instead of strcpy?"

Safer alternative

"In general strncpy is a safer alternative to strcpy"

from question "Do Strong Types prevent Buffer Overflow?"

Safer

"Myth 3 strncpy is a safer version of strcpy"

from question "Why C11 standard doesn't drop unsafe strcat(),strcpy() functions?"

"I was exploring around with c regarding strncpy since most people says that it is safer than strcpy additional parameter length to avoid buffer overflows"

from question "Strncpy & using non-null terminated strings to read stack frame"

"Strncpy is safer than strcpy"

from question "Retrieve value from linked list struct give wrong value"

"Strcpy is notoriously unsafe as are it s cousins strcpy_s and strncpy although they are mildly safer than strcpy"

from question "Is strcpy where src == dest strictly defined?"

"You should use strcpy or strncpy safer than strcpy to copy the string stored in the array between arrays"

from question "Building char array from a string (C)"

Not safer method

"Strncpy is not safer method to use as strcpy"

from question "Valgrind error with strcpy"

Others

Quality Example
Less

"The best solution is to write a custom version of strncpy that is less weird or if you know the length of the input just use strcpy"

from question "C: How to copy over null terminator to structure member, in cleaner way?"

More secure

"So that the strncpy is more secure than strcpy"

from question "Strncpy should only be used with fixed length arrays"

Safier

"Using strncpy is considered safier than strcpy because the second one can easily cause buffer overrun"

from question "Why this code "initialize character" Cant work?"

More

"For instance strncpy is mostly useless it gives you nothing more than strcpy"

from question "Arduino: Empty String when trying to cast a Char[] to String"

"Strncpy is more recommended that strcpy because protect your code against buffer overflow"

from question "Structures and Pointers in C - crash when using strcpy"

Back to Home
Data comes from Stack Exchange with CC-BY-SA-3.0