jlibtool icon indicating copy to clipboard operation
jlibtool copied to clipboard

remove most occurences of strcpy/strcat

Open rofl0r opened this issue 12 years ago • 0 comments

those functions are insecure and in the case of strcat even slow, since the strlen has to be checked on each call. they are considered a code-smell; instead, snprintf should be used.

snprintf(buf, sizeof buf, "%s", mystring) is the only way offered by C99 to do a bounds-checked copy of a string (and after parsing the format string (which should only take a handful of cycles), performance is identical to a naive strcpy implementation using a for loop until 0 is hit).

note that strncpy() always fills the entire buffer, so it is a performance hog.

rofl0r avatar Jul 05 '13 14:07 rofl0r