From ae108d7a69ba6ba5e5bf438425c6fa23d82d3073 Mon Sep 17 00:00:00 2001 From: pancake Date: Fri, 30 Sep 2022 12:47:56 +0200 Subject: [PATCH] Add R_UNUSED_RESULT and use it to avoid unnecessary -Wunused-result warnings --- binr/r2r/run.c | 12 +++++++++--- libr/anal/arch/8051/8051_ass.c | 2 +- libr/include/r_types.h | 2 ++ libr/main/r2pm.c | 8 ++++++-- libr/main/radare2.c | 6 +++--- libr/main/radiff2.c | 10 +++++----- 6 files changed, 26 insertions(+), 14 deletions(-) diff --git a/binr/r2r/run.c b/binr/r2r/run.c index 23a040e6e0..eb61fb4188 100644 --- a/binr/r2r/run.c +++ b/binr/r2r/run.c @@ -415,7 +415,9 @@ static RThread *sigchld_thread; static void handle_sigchld(int sig) { ut8 b = 1; - (void)write (sigchld_pipe[1], &b, 1); + if (write (sigchld_pipe[1], &b, 1) != 1) { + return; + } } static RThreadFunctionRet sigchld_th(RThread *th) { @@ -502,7 +504,9 @@ R_API bool r2r_subprocess_init(void) { R_API void r2r_subprocess_fini(void) { r_sys_signal (SIGCHLD, SIG_IGN); ut8 b = 0; - (void)write (sigchld_pipe[1], &b, 1); + if (write (sigchld_pipe[1], &b, 1) != 1) { + // nothing relevant here + } close (sigchld_pipe [1]); r_th_wait (sigchld_thread); close (sigchld_pipe [0]); @@ -743,7 +747,9 @@ R_API void r2r_subprocess_kill(R2RSubprocess *proc) { } R_API void r2r_subprocess_stdin_write(R2RSubprocess *proc, const ut8 *buf, size_t buf_size) { - (void)write (proc->stdin_fd, buf, buf_size); + if (write (proc->stdin_fd, buf, buf_size) != buf_size) { + // another ignored result + } close (proc->stdin_fd); proc->stdin_fd = -1; } diff --git a/libr/anal/arch/8051/8051_ass.c b/libr/anal/arch/8051/8051_ass.c index 36819116bf..6c295818b9 100644 --- a/libr/anal/arch/8051/8051_ass.c +++ b/libr/anal/arch/8051/8051_ass.c @@ -886,7 +886,7 @@ static bool mnem_jbc(char const*const*arg, ut16 pc, ut8**out) { return false; } - ut16 jmp_addr; + ut16 jmp_addr = 0; if (!to_address (arg[1], &jmp_addr)) { R_LOG_DEBUG ("address %x not found", jmp_addr); return false; diff --git a/libr/include/r_types.h b/libr/include/r_types.h index 1860621295..0e2881d3be 100644 --- a/libr/include/r_types.h +++ b/libr/include/r_types.h @@ -154,6 +154,8 @@ # define UNUSED_FUNCTION(x) UNUSED_ ## x #endif +#define R_UNUSED_RESULT(x) if ((x)) {} + #if defined (__FreeBSD__) || defined (__FreeBSD_kernel__) #define __KFBSD__ 1 #else diff --git a/libr/main/r2pm.c b/libr/main/r2pm.c index d3c813952f..fcf6810917 100644 --- a/libr/main/r2pm.c +++ b/libr/main/r2pm.c @@ -343,13 +343,17 @@ static void r2pm_setenv(void) { r_sys_setenv ("R2PM_PREFIX", r2_prefix); char *pkgcfg = r_sys_getenv ("PKG_CONFIG_PATH"); + char *r2pm_pkgcfg = r_xdg_datadir ("prefix/lib/pkgconfig"); if (R_STR_ISNOTEMPTY (pkgcfg)) { - char *pcp = r_str_newf ("%s:%s", R2_PREFIX "/lib/pkgconfig", pkgcfg); + char *pcp = r_str_newf ("%s:%s:%s", R2_PREFIX "/lib/pkgconfig", r2pm_pkgcfg, pkgcfg); r_sys_setenv ("PKG_CONFIG_PATH", pcp); free (pcp); } else { - r_sys_setenv ("PKG_CONFIG_PATH", R2_PREFIX "/lib/pkgconfig"); + char *pcp = r_str_newf ("%s:%s", r2pm_pkgcfg, R2_PREFIX "/lib/pkgconfig"); + r_sys_setenv ("PKG_CONFIG_PATH", pcp); + free (pcp); } + free (r2pm_pkgcfg); free (pkgcfg); char *bindir = r_str_newf ("%s/bin", r2_prefix); diff --git a/libr/main/radare2.c b/libr/main/radare2.c index 89ae9e1719..77750a87d7 100644 --- a/libr/main/radare2.c +++ b/libr/main/radare2.c @@ -1110,9 +1110,9 @@ R_API int r_main_radare2(int argc, const char **argv) { r_cons_set_raw (false); #if __UNIX__ // TODO: keep flags :? - (void)freopen ("/dev/tty", "rb", stdin); - (void)freopen ("/dev/tty", "w", stdout); - (void)freopen ("/dev/tty", "w", stderr); + R_UNUSED_RESULT (freopen ("/dev/tty", "rb", stdin)); + R_UNUSED_RESULT (freopen ("/dev/tty", "w", stdout)); + R_UNUSED_RESULT (freopen ("/dev/tty", "w", stderr)); #else R_LOG_ERROR ("Cannot reopen stdin without UNIX"); free (buf); diff --git a/libr/main/radiff2.c b/libr/main/radiff2.c index 74e1780402..877ff249ca 100644 --- a/libr/main/radiff2.c +++ b/libr/main/radiff2.c @@ -390,15 +390,15 @@ static int bcb(RDiff *d, void *user, RDiffOp *op) { // we append data if (op->b_len <= 246) { ut8 data = op->b_len; - (void) write (1, &data, 1); + R_UNUSED_RESULT (write (1, &data, 1)); } else if (op->b_len <= USHRT_MAX) { USLen = (ut16) op->b_len; ut8 data = 247; - (void) write (1, &data, 1); + R_UNUSED_RESULT (write (1, &data, 1)); print_bytes (&USLen, sizeof (USLen), true); } else if (op->b_len <= INT_MAX) { ut8 data = 248; - (void) write (1, &data, 1); + R_UNUSED_RESULT (write (1, &data, 1)); ILen = (int) op->b_len; print_bytes (&ILen, sizeof (ILen), true); } else { @@ -1307,7 +1307,7 @@ R_API int r_main_radiff2(int argc, const char **argv) { pj_ka (ro.pj, "changes"); } if (ro.diffmode == 'B') { - (void) write (1, "\xd1\xff\xd1\xff\x04", 5); + R_UNUSED_RESULT (write (1, "\xd1\xff\xd1\xff\x04", 5)); } if (ro.diffmode == 'U') { char *res = r_diff_buffers_unified (d, bufa, (int)sza, bufb, (int)szb); @@ -1318,7 +1318,7 @@ R_API int r_main_radiff2(int argc, const char **argv) { } else if (ro.diffmode == 'B') { r_diff_set_callback (d, &bcb, &ro); r_diff_buffers (d, bufa, (ut32)sza, bufb, (ut32)szb); - (void) write (1, "\x00", 1); + R_UNUSED_RESULT (write (1, "\x00", 1)); } else { r_diff_set_callback (d, &cb, &ro); r_diff_buffers (d, bufa, (ut32)sza, bufb, (ut32)szb);