diff --git a/librz/include/rz_io.h b/librz/include/rz_io.h index 934a3f03340..51c3de97295 100644 --- a/librz/include/rz_io.h +++ b/librz/include/rz_io.h @@ -333,7 +333,7 @@ RZ_API bool rz_io_write(RzIO *io, const ut8 *buf, size_t len); RZ_API ut64 rz_io_size(RzIO *io); RZ_API bool rz_io_is_listener(RzIO *io); RZ_API char *rz_io_system(RzIO *io, const char *cmd); -RZ_API bool rz_io_resize(RzIO *io, ut64 newsize); +RZ_API bool rz_io_resize(RZ_NONNULL RzIO *io, ut64 newsize); RZ_API bool rz_io_extend_at(RzIO *io, ut64 addr, ut64 size); RZ_API bool rz_io_set_write_mask(RzIO *io, const ut8 *mask, size_t len); RZ_API void rz_io_bind(RzIO *io, RzIOBind *bnd); diff --git a/librz/io/io.c b/librz/io/io.c index 24ef79ea7a2..f5edea44a7b 100644 --- a/librz/io/io.c +++ b/librz/io/io.c @@ -422,27 +422,25 @@ RZ_API char *rz_io_system(RzIO *io, const char *cmd) { return NULL; } -RZ_API bool rz_io_resize(RzIO *io, ut64 newsize) { - if (io) { - RzList *maps = rz_io_map_get_for_fd(io, io->desc->fd); - RzIOMap *current_map; - RzListIter *iter; - ut64 fd_size = rz_io_fd_size(io, io->desc->fd); - bool ret = rz_io_desc_resize(io->desc, newsize); - if (!ret) { - rz_list_free(maps); - return false; - } - rz_list_foreach (maps, iter, current_map) { - // we just resize map of the same size of its fd - if (current_map->itv.size == fd_size) { - rz_io_map_resize(io, current_map->id, newsize); - } - } +RZ_API bool rz_io_resize(RZ_NONNULL RzIO *io, ut64 newsize) { + rz_return_val_if_fail(io && io->desc, false); + + RzList *maps = rz_io_map_get_for_fd(io, io->desc->fd); + ut64 fd_size = rz_io_fd_size(io, io->desc->fd); + if (!rz_io_desc_resize(io->desc, newsize)) { rz_list_free(maps); - return true; + return false; } - return false; + RzListIter *iter; + RzIOMap *current_map; + rz_list_foreach (maps, iter, current_map) { + // we just resize map of the same size of its fd + if (current_map->itv.size == fd_size) { + rz_io_map_resize(io, current_map->id, newsize); + } + } + rz_list_free(maps); + return true; } RZ_API bool rz_io_close(RzIO *io) {