xsel

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

commit 1cfdc83c0d38b904daf5f024d023d63b31cd695c
parent ef9a343a78645120a18098b473176ab0884b3265
Author: conrad <conrad@9c49b5d1-7df3-0310-bce2-b7278e68f44c>
Date:   Wed,  5 Dec 2007 07:26:52 +0000

Set CFLAGS to error on warnings when using GCC, and set to gnu99 standard.
However, disable strict-aliasing to allow type-punning on XGetWindowProperty.
Add some casts (unsigned char <-> char) to handle warnings, as suggested by
Axel Liljencrantz (original patch lost, recreated).


git-svn-id: http://svn.kfish.org/xsel/trunk@194 9c49b5d1-7df3-0310-bce2-b7278e68f44c

Diffstat:
Mconfigure.ac | 8++++++++
Mxsel.c | 37+++++++++++++++++++++++++++++--------
2 files changed, 37 insertions(+), 8 deletions(-)

diff --git a/configure.ac b/configure.ac @@ -20,6 +20,14 @@ AC_PATH_XTRA #AC_CHECK_LIB([X11], [XOpenDisplay]) +# Error out on compile warnings +dnl Add some useful warnings if we have gcc. +dnl changequote(,)dnl +if test "x$ac_cv_prog_gcc" = xyes ; then + CFLAGS="$CFLAGS -fno-strict-aliasing -Wall -Werror -g -std=gnu99 -Wdeclaration-after-statement -Wno-unused" +fi +dnl changequote([,])dnl + # Checks for header files. AC_HEADER_STDC AC_CHECK_HEADERS([errno.h fcntl.h stdlib.h string.h sys/time.h unistd.h]) diff --git a/xsel.c b/xsel.c @@ -216,7 +216,7 @@ print_err (const char * fmt, ...) * * Returns a string with a printable name for the Atom 'atom'. */ -static unsigned char * +static char * get_atom_name (Atom atom) { if (atom == None) return "None"; @@ -267,6 +267,27 @@ xs_malloc (size_t size) } /* + * xs_strdup (s) + * + * strdup wrapper for unsigned char * + */ +#define xs_strdup(s) ((unsigned char *) strdup ((const char *)s)) + +/* + * xs_strlen (s) + * + * strlen wrapper for unsigned char * + */ +#define xs_strlen(s) (strlen ((const char *) s)) + +/* + * xs_strncpy (s) + * + * strncpy wrapper for unsigned char * + */ +#define xs_strncpy(dest,src,n) (strncpy ((char *)dest, (const char *)src, n)) + +/* * get_homedir () * * Get the user's home directory. @@ -487,14 +508,14 @@ get_append_property (XSelectionEvent * xsl, unsigned char ** buffer, print_debug (D_TRACE, "Got zero length property; end of INCR transfer"); return False; } else if (format == 8) { - if (*offset + length > *alloc) { + if ((unsigned long)*offset + length > (unsigned long)*alloc) { *alloc = *offset + length; if ((*buffer = realloc (*buffer, *alloc)) == NULL) { exit_err ("realloc error"); } } ptr = *buffer + *offset; - strncpy (ptr, value, length); + xs_strncpy (ptr, value, length); *offset += length; print_debug (D_TRACE, "Appended %d bytes to buffer\n", length); } else { @@ -611,7 +632,7 @@ wait_selection (Atom selection, Atom request_target) retval = NULL; keep_waiting = False; } else { - retval = strdup (value); + retval = xs_strdup (value); XFree (value); keep_waiting = False; } @@ -699,8 +720,8 @@ copy_sel (unsigned char * s) { unsigned char * new_sel = NULL; - new_sel = strdup (s); - current_alloc = total_input = strlen (s); + new_sel = xs_strdup (s); + current_alloc = total_input = xs_strlen (s); return new_sel; } @@ -1266,7 +1287,7 @@ handle_string (Display * display, Window requestor, Atom property, { return change_property (display, requestor, property, XA_STRING, 8, - PropModeReplace, sel, strlen(sel), + PropModeReplace, sel, xs_strlen(sel), selection, time, mparent); } @@ -1282,7 +1303,7 @@ handle_utf8_string (Display * display, Window requestor, Atom property, { return change_property (display, requestor, property, utf8_atom, 8, - PropModeReplace, sel, strlen(sel), + PropModeReplace, sel, xs_strlen(sel), selection, time, mparent); }