Skip to content

Commit

Permalink
Add compiler warnings for some common incorrect usage of functions, s…
Browse files Browse the repository at this point in the history
…uch as forgetting to cast null pointers to variadic functions

darcs-hash:20061019151947-ac50b-4043638a7a830fa80fd918f92365f5afe3ff208a.gz
  • Loading branch information
liljencrantz committed Oct 19, 2006
1 parent ea998b0 commit 2d05b1c
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 8 deletions.
5 changes: 3 additions & 2 deletions common.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions env.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 );


/**
Expand Down
4 changes: 2 additions & 2 deletions exec.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 );


/**
Expand Down
2 changes: 1 addition & 1 deletion expand.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion util.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2d05b1c

Please sign in to comment.