diff --git a/librz/asm/arch/arc/gnu/arc-dis.c b/librz/asm/arch/arc/gnu/arc-dis.c index ff6eab6c958..d04317132a1 100644 --- a/librz/asm/arch/arc/gnu/arc-dis.c +++ b/librz/asm/arch/arc/gnu/arc-dis.c @@ -86,8 +86,9 @@ typedef enum #define PUT_NEXT_WORD_IN(a) \ do \ { \ - if (is_limm == 1 && !NEXT_WORD (1)) \ + if (is_limm == 1 && !NEXT_WORD (1)) { \ mwerror (state, _("Illegal limm reference in last instruction!\n")); \ + } \ (a) = state->words[1]; \ } \ while (0) @@ -257,6 +258,11 @@ arc_sprintf (struct arcDisState *state, char *buf, const char *format, ...) va_start (ap, format); + if (!buf || !format) { + va_end (ap); + return; + } + bp = buf; *bp = 0; p = format; diff --git a/librz/asm/arch/arc/gnu/arcompact-dis.c b/librz/asm/arch/arc/gnu/arcompact-dis.c index c17380b02e8..89f15aa4ca3 100644 --- a/librz/asm/arch/arc/gnu/arcompact-dis.c +++ b/librz/asm/arch/arc/gnu/arcompact-dis.c @@ -99,8 +99,9 @@ static bfd_vma bfd_getm32_ac (unsigned int) ATTRIBUTE_UNUSED; #define FIELDS9_FLAG(word) (((BITS(((signed int)(word)),0,5) << 6) | (BITS((word),6,11))) ) #define PUT_NEXT_WORD_IN(a) { \ - if (is_limm==1 && !NEXT_WORD(1)) \ - mwerror(state, "Illegal limm reference in last instruction!\n"); \ + if (is_limm==1 && !NEXT_WORD(1)) { \ + mwerror(state, "Illegal limm reference in last instruction!\n"); \ + } \ if (info->endian == BFD_ENDIAN_LITTLE) { \ (a) = ((state->words[1] & 0xff00) | (state->words[1] & 0xff)) << 16; \ (a) |= ((state->words[1] & 0xff0000) | (state->words[1] & 0xff000000)) >> 16; \ diff --git a/librz/debug/p/debug_gdb.c b/librz/debug/p/debug_gdb.c index 312e9fb2b34..782b61ee0ed 100644 --- a/librz/debug/p/debug_gdb.c +++ b/librz/debug/p/debug_gdb.c @@ -234,7 +234,7 @@ static RzList *rz_debug_gdb_map_get(RzDebug *dbg) { //TODO snprintf(name, sizeof(name), "unk%d", unk++); } perm = 0; - for (i = 0; perms[i] && i < 5; i++) { + for (i = 0; i < 5 && perms[i]; i++) { switch (perms[i]) { case 'r': perm |= RZ_PERM_R; break; case 'w': perm |= RZ_PERM_W; break; diff --git a/librz/include/rz_syscall.h b/librz/include/rz_syscall.h index eb8e95338e4..4239be3f58e 100644 --- a/librz/include/rz_syscall.h +++ b/librz/include/rz_syscall.h @@ -92,6 +92,7 @@ RZ_API RzSyscallItem *rz_syscall_item_new_from_string(const char *name, const ch RZ_API void rz_syscall_item_free(RzSyscallItem *si); RZ_API RzSyscall *rz_syscall_new(void); +RZ_API void rz_sysregs_db_free(RzSysregsDB *sysregdb); RZ_API void rz_syscall_free(RzSyscall *ctx); RZ_API RzSyscall *rz_syscall_ref(RzSyscall *sc); RZ_API bool rz_syscall_setup(RzSyscall *s, const char *arch, int bits, const char *cpu, const char *os); diff --git a/librz/syscall/syscall.c b/librz/syscall/syscall.c index 4f8c93fe5d0..09f7cb32456 100644 --- a/librz/syscall/syscall.c +++ b/librz/syscall/syscall.c @@ -46,6 +46,17 @@ RZ_API RzSysregsDB *rz_sysregs_db_new() { return sysregdb; } +/** + * \brief Frees a RzSysregDB type + */ +RZ_API void rz_sysregs_db_free(RzSysregsDB *sysregdb) { + if (!sysregdb) { + return; + } + ht_up_free(sysregdb->port); + free(sysregdb); +} + /** * \brief Creates a new RzSyscall type */ @@ -71,6 +82,7 @@ RZ_API void rz_syscall_free(RzSyscall *s) { free(s->os); free(s->cpu); free(s->arch); + rz_sysregs_db_free(s->srdb); free(s); } } @@ -178,7 +190,7 @@ static bool sdb_load_by_path(RZ_NONNULL RzSysregsDB *sysregdb, const char *path) * \param path reference to path of the SDB file */ RZ_API bool rz_sysreg_load_sdb(RzSysregsDB *sysregdb, const char *path) { - if (!rz_file_exists(path)) { + if (!rz_file_exists(path) || !sysregdb) { return false; } return sdb_load_by_path(sysregdb, path); @@ -196,10 +208,10 @@ RZ_API bool rz_sysreg_set_arch(RzSyscall *s, const char *arch, const char *dir_p char *path = sdb_fmt(RZ_JOIN_4_PATHS("%s", RZ_SDB, "reg", "%s-%s-%d.sdb"), dir_prefix, arch, s->cpu, s->bits); - s->srdb = rz_sysregs_db_new(); if (path) { if (!rz_sysreg_load_sdb(s->srdb, path)) { - s->srdb = NULL; + rz_sysregs_db_free(s->srdb); + s->srdb = rz_sysregs_db_new(); return false; } } @@ -252,11 +264,14 @@ RZ_API bool rz_syscall_setup(RzSyscall *s, const char *arch, int bits, const cha } if (sysregs_changed) { + rz_sysregs_db_free(s->srdb); + s->srdb = rz_sysregs_db_new(); char *dbName = rz_str_newf(RZ_JOIN_2_PATHS("reg", "%s-%s-%d"), arch, cpu, bits); if (dbName) { if (!rz_sysreg_load_sdb(s->srdb, dbName)) { - s->srdb = NULL; + rz_sysregs_db_free(s->srdb); + s->srdb = rz_sysregs_db_new(); } free(dbName); } diff --git a/librz/util/print.c b/librz/util/print.c index 14fa9ce8122..ae31112bed6 100644 --- a/librz/util/print.c +++ b/librz/util/print.c @@ -1337,6 +1337,7 @@ RZ_API void rz_print_hexdiff(RzPrint *p, ut64 aa, const ut8 *_a, ut64 ba, const } RZ_API void rz_print_bytes(RzPrint *p, const ut8 *buf, int len, const char *fmt) { + rz_return_if_fail(fmt); int i; if (p) { for (i = 0; i < len; i++) {