From 781ebb44c904d8c815b7017d7070acf1c71f1a22 Mon Sep 17 00:00:00 2001 From: Anton Kochkov Date: Sun, 6 Nov 2022 22:00:53 +0800 Subject: [PATCH] Use size_t instead of int for buffer size --- librz/core/cio.c | 11 +++++------ librz/core/cmd/cmd_print.c | 2 +- librz/include/rz_core.h | 4 ++-- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/librz/core/cio.c b/librz/core/cio.c index 84c20fc5e22..f8c4bb30ae6 100644 --- a/librz/core/cio.c +++ b/librz/core/cio.c @@ -927,9 +927,8 @@ RZ_API bool rz_core_write_string_zero_at(RzCore *core, ut64 addr, const char *s) * \param buflen Used to return the length of the returned buffer * \return The transformed buffer */ -RZ_API RZ_OWN ut8 *rz_core_transform_op(RzCore *core, ut64 addr, RzCoreWriteOp op, ut8 *hex, int hexlen, int *buflen) { +RZ_API RZ_OWN ut8 *rz_core_transform_op(RzCore *core, ut64 addr, RzCoreWriteOp op, RZ_NULLABLE ut8 *hex, size_t hexlen, size_t *buflen) { rz_return_val_if_fail(core, NULL); - rz_return_val_if_fail(!hex || hexlen >= 0, NULL); rz_return_val_if_fail(buflen, NULL); switch (op) { @@ -942,7 +941,7 @@ RZ_API RZ_OWN ut8 *rz_core_transform_op(RzCore *core, ut64 addr, RzCoreWriteOp o case RZ_CORE_WRITE_OP_XOR: case RZ_CORE_WRITE_OP_SHIFT_LEFT: case RZ_CORE_WRITE_OP_SHIFT_RIGHT: - rz_return_val_if_fail(hex && hexlen >= 0, NULL); + rz_return_val_if_fail(hex, NULL); break; default: break; @@ -1017,7 +1016,7 @@ RZ_API RZ_OWN ut8 *rz_core_transform_op(RzCore *core, ut64 addr, RzCoreWriteOp o break; } } - *buflen = len; + *buflen = (size_t)len; return buf; } @@ -1031,8 +1030,8 @@ RZ_API RZ_OWN ut8 *rz_core_transform_op(RzCore *core, ut64 addr, RzCoreWriteOp o * \param hexlen Optional length of the \p hex string. Must be present if \p hex is specified. * \return true if the write operation succeeds, false otherwise */ -RZ_API bool rz_core_write_block_op_at(RzCore *core, ut64 addr, RzCoreWriteOp op, ut8 *hex, int hexlen) { - int buflen; +RZ_API bool rz_core_write_block_op_at(RzCore *core, ut64 addr, RzCoreWriteOp op, ut8 *hex, size_t hexlen) { + size_t buflen; ut8 *buf = rz_core_transform_op(core, addr, op, hex, hexlen, &buflen); if (!buf) { return false; diff --git a/librz/core/cmd/cmd_print.c b/librz/core/cmd/cmd_print.c index 6bd0316089e..82036a805ac 100644 --- a/librz/core/cmd/cmd_print.c +++ b/librz/core/cmd/cmd_print.c @@ -2316,7 +2316,7 @@ static bool cmd_print_pxA(RzCore *core, int len, RzOutputMode mode) { /* Uses data from clipboard if value is NULL */ static bool print_operation_transform(RzCore *core, RzCoreWriteOp op, RZ_NULLABLE const char *val) { ut8 *hex = NULL; - int hexlen = -1, buflen = -1; + size_t hexlen = 0, buflen = 0; if (val) { hex = RZ_NEWS(ut8, (strlen(val) + 1) / 2); if (!hex) { diff --git a/librz/include/rz_core.h b/librz/include/rz_core.h index 24ae8809599..1044b54f680 100644 --- a/librz/include/rz_core.h +++ b/librz/include/rz_core.h @@ -545,9 +545,9 @@ RZ_API bool rz_core_write_length_string_at(RzCore *core, ut64 addr, const char * RZ_API bool rz_core_write_base64d_at(RzCore *core, ut64 addr, RZ_NONNULL const char *s); RZ_API bool rz_core_write_base64_at(RzCore *core, ut64 addr, RZ_NONNULL const char *s); RZ_API bool rz_core_write_random_at(RzCore *core, ut64 addr, size_t len); -RZ_API bool rz_core_write_block_op_at(RzCore *core, ut64 addr, RzCoreWriteOp op, ut8 *hex, int hexlen); +RZ_API bool rz_core_write_block_op_at(RzCore *core, ut64 addr, RzCoreWriteOp op, RZ_NULLABLE ut8 *hex, size_t hexlen); RZ_API bool rz_core_write_duplicate_at(RzCore *core, ut64 addr, ut64 from, int len); -RZ_API RZ_OWN ut8 *rz_core_transform_op(RzCore *core, ut64 addr, RzCoreWriteOp op, ut8 *hex, int hexlen, int *buflen); +RZ_API RZ_OWN ut8 *rz_core_transform_op(RzCore *core, ut64 addr, RzCoreWriteOp op, RZ_NULLABLE ut8 *hex, size_t hexlen, size_t *buflen); RZ_API ut32 rz_core_file_cur_fd(RzCore *core); RZ_API RzCmdStatus rz_core_io_cache_print(RzCore *core, RzCmdStateOutput *state); RZ_API RzCmdStatus rz_core_io_pcache_print(RzCore *core, RzIODesc *desc, RzCmdStateOutput *state);