Skip to content

Commit

Permalink
Merge pull request #32 from ony/master
Browse files Browse the repository at this point in the history
Avoid extra char copy in strncpy
  • Loading branch information
kfish authored May 17, 2019
2 parents 9bfc13d + d88aa9a commit 24bee9c
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions xsel.c
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,8 @@ static char *
get_atom_name (Atom atom)
{
char * ret;
static char atom_name[MAXLINE+1];
static char atom_name[MAXLINE+2]; /* unused extra char to avoid
string-op-truncation warning */

if (atom == None) return "None";
if (atom == XA_STRING) return "STRING";
Expand All @@ -249,7 +250,7 @@ get_atom_name (Atom atom)
if (atom == utf8_atom) return "UTF8_STRING";

ret = XGetAtomName (display, atom);
strncpy (atom_name, ret, sizeof (atom_name));
strncpy (atom_name, ret, MAXLINE+1);
if (atom_name[MAXLINE] != '\0')
{
atom_name[MAXLINE-3] = '.';
Expand Down Expand Up @@ -328,7 +329,7 @@ static char *
_xs_strncpy (char * dest, const char * src, size_t n)
{
if (n > 0) {
strncpy (dest, src, n);
strncpy (dest, src, n-1);
dest[n-1] = '\0';
}
return dest;
Expand Down

0 comments on commit 24bee9c

Please sign in to comment.