From beec29c3054acc262ac2dbef5b29c1e279a6fdb3 Mon Sep 17 00:00:00 2001 From: David Leadbeater Date: Sun, 6 Jul 2014 18:56:17 +0100 Subject: [PATCH 1/4] Make configure checks able to build with -Werror Also fix a few compiler warnings, this combined with pull #82 allows me to build with CFLAGS="-Werror -Wall". --- configure.ac | 8 +++++--- src/core/network.c | 2 +- src/fe-text/gui-entry.c | 2 +- src/fe-text/term-terminfo.c | 4 ++-- src/fe-text/textbuffer-view.c | 5 +++-- src/perl/textui/Statusbar.xs | 3 +-- 6 files changed, 13 insertions(+), 11 deletions(-) diff --git a/configure.ac b/configure.ac index 04c50b4b..40171a03 100644 --- a/configure.ac +++ b/configure.ac @@ -221,7 +221,7 @@ AC_CACHE_VAL(irssi_cv_type_socklen_t, [AC_TRY_COMPILE([ #include #include ], -[socklen_t t;], +[socklen_t t = 0; return((int)t); ], irssi_cv_type_socklen_t=yes, irssi_cv_type_socklen_t=no, )]) @@ -455,8 +455,10 @@ if test "$want_perl" != "no"; then esac dnl * check that perl's ldflags actually work - echo "main(){perl_alloc(); return 0;}" > conftest.c - $CC $CFLAGS conftest.c -o conftest $LDFLAGS $PERL_LDFLAGS 2> perl.error.tmp > /dev/null + echo "#include " > conftest.c + echo "#include " >> conftest.c + echo "int main(){perl_alloc(); return 0;}" >> conftest.c + $CC $CFLAGS $PERL_CFLAGS conftest.c -o conftest $LDFLAGS $PERL_LDFLAGS 2> perl.error.tmp > /dev/null if test ! -s conftest -a "x$ignore_perl_errors" = "x"; then perl_check_error="Error linking with perl libraries: $PERL_LDFLAGS: `cat perl.error.tmp`" AC_MSG_RESULT([error linking with perl libraries, building without Perl]) diff --git a/src/core/network.c b/src/core/network.c index 7e55d472..de5abbbe 100644 --- a/src/core/network.c +++ b/src/core/network.c @@ -60,7 +60,7 @@ GIOChannel *g_io_channel_new(int handle) IPADDR ip4_any = { AF_INET, - { { { INADDR_ANY } } } + { INADDR_ANY } }; int net_ip_compare(IPADDR *ip1, IPADDR *ip2) diff --git a/src/fe-text/gui-entry.c b/src/fe-text/gui-entry.c index 13cbfafd..f123ce4c 100644 --- a/src/fe-text/gui-entry.c +++ b/src/fe-text/gui-entry.c @@ -452,7 +452,7 @@ void gui_entry_insert_text(GUI_ENTRY_REC *entry, const char *str) g_utf8_validate(str, -1, &ptr); len = g_utf8_pointer_to_offset(str, ptr); } else if (term_type == TERM_TYPE_BIG5) - len = strlen_big5(str); + len = strlen_big5((const unsigned char *)str); else len = strlen(str); entry_text_grow(entry, len); diff --git a/src/fe-text/term-terminfo.c b/src/fe-text/term-terminfo.c index 2ca2f347..6459ce75 100644 --- a/src/fe-text/term-terminfo.c +++ b/src/fe-text/term-terminfo.c @@ -140,7 +140,7 @@ int term_init(void) term_set_input_type(TERM_TYPE_8BIT); term_common_init(); - g_atexit(term_deinit); + atexit(term_deinit); return TRUE; } @@ -568,7 +568,7 @@ void term_stop(void) static int input_utf8(const unsigned char *buffer, int size, unichar *result) { - unichar c = g_utf8_get_char_validated(buffer, size); + unichar c = g_utf8_get_char_validated((char *)buffer, size); switch (c) { case (unichar)-1: diff --git a/src/fe-text/textbuffer-view.c b/src/fe-text/textbuffer-view.c index 81deaf54..b240742c 100644 --- a/src/fe-text/textbuffer-view.c +++ b/src/fe-text/textbuffer-view.c @@ -22,6 +22,7 @@ #include "module.h" #include "textbuffer-view.h" +#include "signals.h" #include "utf8.h" typedef struct { @@ -178,14 +179,14 @@ static void unformat_24bit_line_color(const unsigned char **ptr, int off, int *f static inline unichar read_unichar(const unsigned char *data, const unsigned char **next, int *width) { - unichar chr = g_utf8_get_char_validated(data, -1); + unichar chr = g_utf8_get_char_validated((const char *) data, -1); if (chr & 0x80000000) { chr = 0xfffd; *next = data + 1; *width = 1; } else { - *next = g_utf8_next_char(data); + *next = (unsigned char *)g_utf8_next_char(data); *width = unichar_isprint(chr) ? mk_wcwidth(chr) : 1; } return chr; diff --git a/src/perl/textui/Statusbar.xs b/src/perl/textui/Statusbar.xs index d904ae9f..620fad9a 100644 --- a/src/perl/textui/Statusbar.xs +++ b/src/perl/textui/Statusbar.xs @@ -50,7 +50,6 @@ static void perl_statusbar_event(char *function, SBAR_ITEM_REC *item, int get_size_only) { dSP; - int retcount; SV *item_sv, **sv; HV *hv; @@ -63,7 +62,7 @@ static void perl_statusbar_event(char *function, SBAR_ITEM_REC *item, XPUSHs(sv_2mortal(newSViv(get_size_only))); PUTBACK; - retcount = perl_call_pv(function, G_EVAL|G_DISCARD); + perl_call_pv(function, G_EVAL|G_DISCARD); SPAGAIN; if (SvTRUE(ERRSV)) { From 7949e4c53f8bc8cb0b28f38b7a08db49a00f8b01 Mon Sep 17 00:00:00 2001 From: David Leadbeater Date: Sun, 6 Jul 2014 19:56:13 +0100 Subject: [PATCH 2/4] Initialize in6 correctly This is technically wrong as it then gets used as an IPv4 sockaddr, but it only needs to be some 0s so this is easier than changing the IPADDR data structure or adding a new API. --- src/core/network.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/core/network.c b/src/core/network.c index de5abbbe..3659ab36 100644 --- a/src/core/network.c +++ b/src/core/network.c @@ -60,7 +60,11 @@ GIOChannel *g_io_channel_new(int handle) IPADDR ip4_any = { AF_INET, +#if defined(HAVE_IPV6) && defined(IN6ADDR_ANY_INIT) + IN6ADDR_ANY_INIT +#else { INADDR_ANY } +#endif }; int net_ip_compare(IPADDR *ip1, IPADDR *ip2) From 85d9fa1922a5f408dd40f18287f01135dd826e4d Mon Sep 17 00:00:00 2001 From: David Leadbeater Date: Sun, 6 Jul 2014 21:51:22 +0100 Subject: [PATCH 3/4] Fix compiler warning in IPv6 check (This was why I saw a warning from the IPv4 code path, now fixed by 7949e4c). --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 40171a03..29fee0bd 100644 --- a/configure.ac +++ b/configure.ac @@ -628,7 +628,7 @@ if test "x$want_ipv6" = "xyes"; then #include #include #include ], - [struct in6_addr i;], + [struct in6_addr i = in6addr_any; return &i == &i;], have_ipv6=yes, )]) if test $have_ipv6 = yes; then From dac67a567d8c1ffc63a38f94349ea37d2dc4f2c1 Mon Sep 17 00:00:00 2001 From: David Leadbeater Date: Sun, 6 Jul 2014 21:52:03 +0100 Subject: [PATCH 4/4] Check return values from some syscalls and warn if they fail --- src/core/commands.c | 4 +++- src/core/rawlog.c | 11 ++++++++--- src/core/write-buffer.c | 4 +++- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/core/commands.c b/src/core/commands.c index 547f7b16..ed82f44e 100644 --- a/src/core/commands.c +++ b/src/core/commands.c @@ -968,7 +968,9 @@ static void cmd_cd(const char *data) if (*data == '\0') return; str = convert_home(data); - chdir(str); + if (chdir(str) != 0) { + g_warning("Failed to chdir(): %s", strerror(errno)); + } g_free(str); } diff --git a/src/core/rawlog.c b/src/core/rawlog.c index 20368aeb..e66f20dd 100644 --- a/src/core/rawlog.c +++ b/src/core/rawlog.c @@ -102,10 +102,15 @@ void rawlog_redirect(RAWLOG_REC *rawlog, const char *str) static void rawlog_dump(RAWLOG_REC *rawlog, int f) { GSList *tmp; + ssize_t ret = 1; - for (tmp = rawlog->lines; tmp != NULL; tmp = tmp->next) { - write(f, tmp->data, strlen((char *) tmp->data)); - write(f, "\n", 1); + for (tmp = rawlog->lines; ret && tmp != NULL; tmp = tmp->next) { + ret = write(f, tmp->data, strlen((char *) tmp->data)); + ret &= write(f, "\n", 1); + } + + if (ret <= 0) { + g_warning("rawlog write() failed: %s", strerror(errno)); } } diff --git a/src/core/write-buffer.c b/src/core/write-buffer.c index 6f6eef8a..ffc3ae63 100644 --- a/src/core/write-buffer.c +++ b/src/core/write-buffer.c @@ -107,7 +107,9 @@ static int write_buffer_flush_rec(void *handlep, BUFFER_REC *rec) for (tmp = rec->blocks; tmp != NULL; tmp = tmp->next) { size = tmp->data != rec->active_block ? BUFFER_BLOCK_SIZE : rec->active_block_pos; - write(handle, tmp->data, size); + if (write(handle, tmp->data, size) != size) { + g_warning("Failed to write(): %s", strerror(errno)); + } } empty_blocks = g_slist_concat(empty_blocks, rec->blocks);