xsel

Program for manipulating the X clipboard
git clone https://git.sinitax.com/kfish/xsel
Log | Files | Refs | README | LICENSE | sfeed.txt

commit d88aa9a8dba9228e6780d6bb5a5720a36f854918
parent 9bfc13d64b5acb92c6648c696a9d9260fcbecc65
Author: Mykola Orliuk <virkony@gmail.com>
Date:   Sun,  5 May 2019 23:29:10 +0200

Avoid extra char copy in strncpy

Also reserve unused extra char in get_atom_name to avoid gcc 8.3.0 error like:
'strncpy' specified bound 4098 equals destination size [-Werror=stringop-truncation]

Diffstat:
Mxsel.c | 7++++---
1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/xsel.c b/xsel.c @@ -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"; @@ -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] = '.'; @@ -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;