From 306d6aa996b0e42f7410a9d39b2122ae58c199f9 Mon Sep 17 00:00:00 2001 From: pancake Date: Sun, 31 Jan 2021 19:50:40 +0100 Subject: [PATCH] Fix few warnings and sort w command switch --- libr/bin/p/bin_wasm.c | 2 +- libr/core/cmd_write.c | 36 +++++++++++++++++++----------------- 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/libr/bin/p/bin_wasm.c b/libr/bin/p/bin_wasm.c index 5c5b431603..7c2524cf0d 100644 --- a/libr/bin/p/bin_wasm.c +++ b/libr/bin/p/bin_wasm.c @@ -23,7 +23,7 @@ static bool find_export(const ut32 *p, const RBinWasmExportEntry *q) { } static bool load_buffer(RBinFile *bf, void **bin_obj, RBuffer *buf, ut64 loadaddr, Sdb *sdb) { - r_return_val_if_fail (bf && buf && r_buf_size (buf) != UT64_MAX, NULL); + r_return_val_if_fail (bf && buf && r_buf_size (buf) != UT64_MAX, false); if (check_buffer (buf)) { *bin_obj = r_bin_wasm_init (bf, buf); diff --git a/libr/core/cmd_write.c b/libr/core/cmd_write.c index 57bf09f905..12909d3878 100644 --- a/libr/core/cmd_write.c +++ b/libr/core/cmd_write.c @@ -1,4 +1,4 @@ -/* radare - LGPL - Copyright 2009-2020 - pancake */ +/* radare - LGPL - Copyright 2009-2021 - pancake */ #include "r_crypto.h" #include "r_config.h" @@ -1867,8 +1867,9 @@ static int wa_handler_old(void *data, const char *input) { static int wb_handler_old(void *data, const char *input) { RCore *core = (RCore *)data; - int len = strlen (input); - ut8 *buf = malloc (len + 2); + size_t len = strlen (input); + const size_t buf_size = len + 2; + ut8 *buf = malloc (buf_size); int wseek = r_config_get_i (core->config, "cfg.wseek"); if (buf) { len = r_hex_str2bin (input, buf); @@ -1880,11 +1881,12 @@ static int wb_handler_old(void *data, const char *input) { WSEEK (core, core->blocksize); } r_core_block_read (core); - } else + } else { eprintf ("Wrong argument\n"); + } free (buf); } else { - eprintf ("Cannot malloc %d\n", len + 1); + eprintf ("Cannot malloc %zd\n", buf_size); } return 0; } @@ -1980,9 +1982,6 @@ static int cmd_write(void *data, const char *input) { } switch (*input) { - case 'B': // "wB" - wB_handler_old (data, input + 1); - break; case '0': // "w0" w0_handler_old (data, input + 1); break; @@ -1995,6 +1994,18 @@ static int cmd_write(void *data, const char *input) { case '6': // "w6" w6_handler_old (core, input + 1); break; + case 'a': // "wa" + wa_handler_old (core, input + 1); + break; + case 'b': // "wb" + wb_handler_old (core, input + 1); + break; + case 'B': // "wB" + wB_handler_old (data, input + 1); + break; + case 'c': // "wc" + wc_handler_old (core, input + 1); + break; case 'h': // "wh" wh_handler_old (core, input + 1); break; @@ -2013,9 +2024,6 @@ static int cmd_write(void *data, const char *input) { case 'A': // "wA" wA_handler_old (core, input + 1); break; - case 'c': // "wc" - wc_handler_old (core, input + 1); - break; case ' ': // "w" w_handler_old (core, input + 1); break; @@ -2034,12 +2042,6 @@ static int cmd_write(void *data, const char *input) { case 'x': // "wx" wx_handler_old (core, input + 1); break; - case 'a': // "wa" - wa_handler_old (core, input + 1); - break; - case 'b': // "wb" - wb_handler_old (core, input + 1); - break; case 'm': // "wm" wm_handler_old (core, input + 1); break;