From 2d05b1c1b4cf51df30903a24d1d7944aa1b8eeb7 Mon Sep 17 00:00:00 2001 From: axel Date: Fri, 20 Oct 2006 01:19:47 +1000 Subject: [PATCH] Add compiler warnings for some common incorrect usage of functions, such as forgetting to cast null pointers to variadic functions darcs-hash:20061019151947-ac50b-4043638a7a830fa80fd918f92365f5afe3ff208a.gz --- common.h | 5 +++-- configure.ac | 9 +++++++++ env.h | 4 ++-- exec.h | 4 ++-- expand.h | 2 +- util.h | 2 +- 6 files changed, 18 insertions(+), 8 deletions(-) diff --git a/common.h b/common.h index d9c7cc274..2cefd584e 100644 --- a/common.h +++ b/common.h @@ -106,6 +106,7 @@ extern wchar_t *program_name; */ #define N_(wstr) wstr + /** Take an array_list_t containing wide strings and converts them to a single null-terminated wchar_t **. The array is allocated using @@ -193,7 +194,7 @@ wchar_t *wcsdupcat( const wchar_t *a, const wchar_t *b ); Returns a newly allocated concatenation of the specified wide character strings. The last argument must be a null pointer. */ -wchar_t *wcsdupcat2( const wchar_t *a, ... ); +__sentinel wchar_t *wcsdupcat2( const wchar_t *a, ... ); /** Test if the given string is a valid variable name @@ -256,7 +257,7 @@ const wchar_t *wsetlocale( int category, const wchar_t *locale ); \return zero is needle is not found, of if needle is null, non-zero otherwise */ -int contains_str( const wchar_t *needle, ... ); +__sentinel int contains_str( const wchar_t *needle, ... ); /** Call read while blocking the SIGCHLD signal. Should only be called diff --git a/configure.ac b/configure.ac index 6af096a04..c0699a29f 100644 --- a/configure.ac +++ b/configure.ac @@ -92,6 +92,15 @@ AC_SUBST( optbindirs, $optbindirs ) # Tell autoconf to create config.h header AC_CONFIG_HEADERS(config.h) +AH_BOTTOM([#if __GNUC__ >= 3 +#define __warn_unused __attribute__ ((warn_unused_result)) +#define __sentinel __attribute__ ((sentinel)) +#else +#define __warn_unused +#define __sentinel +#endif]) + + # Set up various programs needed for install AC_PROG_CC AC_PROG_CPP diff --git a/env.h b/env.h index ea59ecabf..e192fde49 100644 --- a/env.h +++ b/env.h @@ -80,8 +80,8 @@ void env_destroy(); */ int env_set( const wchar_t *key, - const wchar_t *val, - int mode ); + const wchar_t *val, + int mode ); /** diff --git a/exec.h b/exec.h index 97345e981..63e0d0a36 100644 --- a/exec.h +++ b/exec.h @@ -51,8 +51,8 @@ void exec( job_t *j ); \return the status of the last job to exit, or -1 if en error was encountered. */ -int exec_subshell( const wchar_t *cmd, - array_list_t *l ); +__warn_unused int exec_subshell( const wchar_t *cmd, + array_list_t *l ); /** diff --git a/expand.h b/expand.h index 9fb6c240b..7486e9c7b 100644 --- a/expand.h +++ b/expand.h @@ -139,7 +139,7 @@ enum \param out The list to which the result will be appended. \return One of EXPAND_OK, EXPAND_ERROR, EXPAND_WILDCARD_MATCH and EXPAND_WILDCARD_NO_MATCH. EXPAND_WILDCARD_NO_MATCH and EXPAND_WILDCARD_MATCH are normal exit conditions used only on strings containing wildcards to tell if the wildcard produced any matches. */ -int expand_string( void *context, wchar_t *in, array_list_t *out, int flag ); +__warn_unused int expand_string( void *context, wchar_t *in, array_list_t *out, int flag ); /** expand_one is identical to expand_string, except it will fail if in diff --git a/util.h b/util.h index 9f9655085..27f25c0e7 100644 --- a/util.h +++ b/util.h @@ -607,7 +607,7 @@ void sb_append_char( string_buffer_t *, wchar_t ); Do not forget to cast the last 0 to (void *), or you might encounter errors on 64-bit platforms! */ -void sb_append2( string_buffer_t *, ... ); +__sentinel void sb_append2( string_buffer_t *, ... ); /** Append formated string data to the buffer. This function internally