Skip to content

Commit

Permalink
Use size_t instead of int for buffer size
Browse files Browse the repository at this point in the history
  • Loading branch information
XVilka committed Nov 6, 2022
1 parent 15046c0 commit 572a264
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
11 changes: 5 additions & 6 deletions librz/core/cio.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}

Expand All @@ -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, RZ_NULLABLE ut8 *hex, size_t hexlen) {
size_t buflen;
ut8 *buf = rz_core_transform_op(core, addr, op, hex, hexlen, &buflen);
if (!buf) {
return false;
Expand Down
2 changes: 1 addition & 1 deletion librz/core/cmd/cmd_print.c
Original file line number Diff line number Diff line change
Expand Up @@ -2315,7 +2315,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) {
Expand Down
4 changes: 2 additions & 2 deletions librz/include/rz_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 572a264

Please sign in to comment.