Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove most occurences of strcpy/strcat #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

rofl0r
Copy link

@rofl0r rofl0r commented Jul 5, 2013

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.

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.
* pathlen denotes the length of its path prefix.
* in other words, arg + pathname = start of filename.
* we're only interested in the path part of the filename here. */
static char * load_noinstall_path(const char *arg, size_t pathlen)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note that using size_t is needed whenever dealing with sizes: http://ewontfix.com/9/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant