Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix compiler warnings gnu/arc*.c syscall.c print.c debug_gdb.c #1227

Merged
merged 5 commits into from
Jun 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion librz/asm/arch/arc/gnu/arc-dis.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)) { \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, i know.

mwerror (state, _("Illegal limm reference in last instruction!\n")); \
} \
(a) = state->words[1]; \
} \
while (0)
Expand Down Expand Up @@ -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;
Expand Down
5 changes: 3 additions & 2 deletions librz/asm/arch/arc/gnu/arcompact-dis.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)) { \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one as well.

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; \
Expand Down
2 changes: 1 addition & 1 deletion librz/debug/p/debug_gdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions librz/include/rz_syscall.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
23 changes: 19 additions & 4 deletions librz/syscall/syscall.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -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);
}
}
Expand Down Expand Up @@ -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);
Expand All @@ -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;
}
}
Expand Down Expand Up @@ -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);
}
Expand Down
1 change: 1 addition & 0 deletions librz/util/print.c
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand Down