Fix few clang-cl warnings

This commit is contained in:
Riccardo Schirone 2021-09-04 00:39:32 +02:00 committed by Riccardo Schirone
parent aed6854bdf
commit 6aef990eef
14 changed files with 42 additions and 85 deletions

View file

@ -27,8 +27,8 @@ static bool download_and_write(SPDBDownloaderOpt *opt, const char *file) {
char *path = rz_str_newf("%s%s%s", dir, RZ_SYS_DIR, opt->dbg_file);
#if __WINDOWS__
if (rz_str_startswith(url, "\\\\")) { // Network path
LPCWSTR origin = rz_utf8_to_utf16(url);
LPCWSTR dest = rz_utf8_to_utf16(path);
wchar_t *origin = rz_utf8_to_utf16(url);
wchar_t *dest = rz_utf8_to_utf16(path);
BOOL ret = CopyFileW(origin, dest, FALSE);
free(dir);
free(path);

View file

@ -207,16 +207,16 @@ static int rz_line_readchar_utf8(ut8 *s, int slen) {
#if __WINDOWS__
static int rz_line_readchar_win(ut8 *s, int slen) { // this function handle the input in console mode
if (slen > 0 && rz_cons_readbuffer_readchar(s)) {
if (s[0] == '\x1b' && rz_cons_readbuffer_readchar(s + 1)) {
if (s[1] == '\x31' && rz_cons_readbuffer_readchar(s + 2)) {
if (slen > 0 && rz_cons_readbuffer_readchar((char *)s)) {
if (s[0] == '\x1b' && rz_cons_readbuffer_readchar((char *)s + 1)) {
if (s[1] == '\x31' && rz_cons_readbuffer_readchar((char *)s + 2)) {
return 3;
}
return 2;
}
return 1;
}
INPUT_RECORD irInBuf = { { 0 } };
INPUT_RECORD irInBuf = { 0 };
BOOL ret, bCtrl = FALSE;
DWORD mode, out;
char buf[5] = { 0 };

View file

@ -1705,50 +1705,6 @@ RZ_IPI int rz_cmd_env(void *data, const char *input) {
return ret;
}
static struct autocomplete_flag_map_t {
const char *name;
const char *desc;
int type;
} autocomplete_flags[] = {
{ "$dflt", "default autocomplete flag", RZ_CORE_AUTOCMPLT_DFLT },
{ "$flag", "shows known flag hints", RZ_CORE_AUTOCMPLT_FLAG },
{ "$flsp", "shows known flag-spaces hints", RZ_CORE_AUTOCMPLT_FLSP },
{ "$seek", "shows the seek hints", RZ_CORE_AUTOCMPLT_SEEK },
{ "$fcn", "shows the functions hints", RZ_CORE_AUTOCMPLT_FCN },
{ "$zign", "shows known zignatures hints", RZ_CORE_AUTOCMPLT_ZIGN },
{ "$eval", "shows known evals hints", RZ_CORE_AUTOCMPLT_EVAL },
{ "$mins", NULL, RZ_CORE_AUTOCMPLT_MINS },
{ "$brkp", "shows known breakpoints hints", RZ_CORE_AUTOCMPLT_BRKP },
{ "$macro", NULL, RZ_CORE_AUTOCMPLT_MACR },
{ "$file", "hints file paths", RZ_CORE_AUTOCMPLT_FILE },
{ "$thme", "shows known themes hints", RZ_CORE_AUTOCMPLT_THME },
{ "$optn", "allows the selection for multiple options", RZ_CORE_AUTOCMPLT_OPTN },
{ "$sdb", "shows sdb hints", RZ_CORE_AUTOCMPLT_SDB },
{ NULL, NULL, 0 }
};
static inline void print_dict(RzCoreAutocomplete *a, int sub) {
if (!a) {
return;
}
int i, j;
const char *name = "unknown";
for (i = 0; i < a->n_subcmds; i++) {
RzCoreAutocomplete *b = a->subcmds[i];
if (b->locked) {
continue;
}
for (j = 0; j < RZ_CORE_AUTOCMPLT_END; j++) {
if (b->type == autocomplete_flags[j].type) {
name = autocomplete_flags[j].name;
break;
}
}
eprintf("[%3d] %s: '%s'\n", sub, name, b->cmd);
print_dict(a->subcmds[i], sub + 1);
}
}
RZ_IPI RzCmdStatus rz_cmd_exit_handler(RzCore *core, int argc, const char **argv) {
core->num->value = 0LL;
return RZ_CMD_STATUS_EXIT;

View file

@ -2424,8 +2424,8 @@ void __move_panel_to_left(RzCore *core, RzPanel *panel, int src) {
int i = 1;
for (; i < panels->n_panels; i++) {
RzPanel *tmp = __get_panel(panels, i);
int t_x = ((double)tmp->view->pos.x / (double)w) * (double)new_w + p_w;
int t_w = ((double)tmp->view->pos.w / (double)w) * (double)new_w + 1;
int t_x = (int)(((double)tmp->view->pos.x / (double)w) * (double)new_w + p_w);
int t_w = (int)(((double)tmp->view->pos.w / (double)w) * (double)new_w + 1);
__set_geometry(&tmp->view->pos, t_x, tmp->view->pos.y, t_w, tmp->view->pos.h);
}
__fix_layout(core);

View file

@ -54,7 +54,7 @@ static bool __is_target_kernel(DbgEngContext *idbg) {
return false;
}
static bool windbg_init(RzDebug *dbg) {
static bool windbg_init(RzDebug *dbg, void **user) {
DbgEngContext *idbg = dbg->plugin_data;
if (!idbg || !idbg->initialized) {
return false;

View file

@ -438,7 +438,6 @@ int w32_reg_read(RzDebug *dbg, int type, ut8 *buf, int size) {
type = -type;
}
bool alive = is_thread_alive(dbg, dbg->tid);
W32DbgWInst *wrap = dbg->plugin_data;
HANDLE th = get_thread_handle_from_tid(dbg, dbg->tid);
if (!th || th == INVALID_HANDLE_VALUE) {
return 0;
@ -473,7 +472,6 @@ int w32_reg_write(RzDebug *dbg, int type, const ut8 *buf, int size) {
if (!alive) {
return false;
}
W32DbgWInst *wrap = dbg->plugin_data;
HANDLE th = get_thread_handle_from_tid(dbg, dbg->tid);
if (!th || th == INVALID_HANDLE_VALUE) {
return 0;
@ -516,7 +514,6 @@ int w32_attach(RzDebug *dbg, int pid) {
wrap->pi.dwProcessId = 0;
return -1;
}
int ret;
dbg->cur->wait(dbg, pid);
rz_debug_continue(dbg);
return wrap->pi.dwThreadId;

View file

@ -316,12 +316,12 @@ static int __close(RzIODesc *fd) {
return 0;
}
static void got_alarm(int sig) {
#if !defined(__WINDOWS__)
static void got_alarm(int sig) {
// !!! may die if not running from r2preload !!! //
kill(getpid(), SIGUSR1);
#endif
}
#endif
static char *__system(RzIO *io, RzIODesc *fd, const char *cmd) {
if (!strcmp(cmd, "pid")) {

View file

@ -89,7 +89,7 @@ static bool __plugin_open(RzIO *io, const char *file, bool many) {
return !strncmp(file, "w32dbg://", 9);
}
static inline current_handle_valid(W32DbgWInst *wrap, int pid) {
static inline bool current_handle_valid(W32DbgWInst *wrap, int pid) {
return wrap->pi.dwProcessId == pid && wrap->pi.hProcess != INVALID_HANDLE_VALUE;
}

View file

@ -41,7 +41,7 @@ static HANDLE hproc = NULL;
static void lang_pipe_run_win(RzLang *lang) {
CHAR buf[PIPE_BUF_SIZE];
BOOL bSuccess = TRUE;
int i, res = 0;
int i;
DWORD dwRead = 0, dwWritten = 0, dwEvent;
HANDLE hRead = CreateEvent(NULL, TRUE, FALSE, NULL);
if (!hRead) {

View file

@ -22,8 +22,13 @@
#endif
#define BS 1024
#ifdef __WINDOWS__
#define StructStat struct _stat
#else
#define StructStat struct stat
#endif
static int file_stat(const char *file, struct stat *const pStat) {
static int file_stat(const char *file, StructStat *pStat) {
rz_return_val_if_fail(file && pStat, -1);
#if __WINDOWS__
wchar_t *wfile = rz_utf8_to_utf16(file);
@ -131,7 +136,7 @@ RZ_API bool rz_file_is_c(const char *file) {
}
RZ_API bool rz_file_is_regular(const char *str) {
struct stat buf = { 0 };
StructStat buf = { 0 };
if (!str || !*str || file_stat(str, &buf) == -1) {
return false;
}
@ -139,7 +144,7 @@ RZ_API bool rz_file_is_regular(const char *str) {
}
RZ_API bool rz_file_is_directory(const char *str) {
struct stat buf = { 0 };
StructStat buf = { 0 };
rz_return_val_if_fail(!RZ_STR_ISEMPTY(str), false);
if (file_stat(str, &buf) == -1) {
return false;
@ -166,7 +171,7 @@ RZ_API bool rz_file_fexists(const char *fmt, ...) {
RZ_API bool rz_file_exists(const char *str) {
rz_return_val_if_fail(!RZ_STR_ISEMPTY(str), false);
char *absfile = rz_file_abspath(str);
struct stat buf = { 0 };
StructStat buf = { 0 };
if (file_stat(absfile, &buf) == -1) {
free(absfile);
@ -178,7 +183,7 @@ RZ_API bool rz_file_exists(const char *str) {
RZ_API ut64 rz_file_size(const char *str) {
rz_return_val_if_fail(!RZ_STR_ISEMPTY(str), 0);
struct stat buf = { 0 };
StructStat buf = { 0 };
if (file_stat(str, &buf) == -1) {
return 0;
}
@ -874,7 +879,6 @@ repeat:
static RzMmap *file_mmap(RzMmap *m) {
LPTSTR file_ = rz_sys_conv_utf8_to_win(m->filename);
bool is_write = (m->perm & O_WRONLY) || (m->perm & O_RDWR);
bool is_creat = m->perm & O_CREAT;
HANDLE fh = (HANDLE)_get_osfhandle(m->fd);
m->len = (DWORD)GetFileSize(fh, (LPDWORD)((char *)&m->len + sizeof(DWORD)));
if (m->len == INVALID_FILE_SIZE) {

View file

@ -175,7 +175,7 @@ RZ_API RzSubprocess *rz_subprocess_start_opt(RzSubprocessOpt *opt) {
if (opt->args_size) {
memcpy(argv + 1, opt->args, sizeof(char *) * opt->args_size);
}
char *cmd = rz_str_format_msvc_argv(opt->args_size + 1, argv);
char *cmd = rz_str_format_msvc_argv(opt->args_size + 1, (const char **)argv);
free(argv);
if (!cmd) {
return NULL;
@ -298,7 +298,7 @@ error:
goto beach;
}
static bool do_read(HANDLE *f, ut8 *buf, size_t buf_size, size_t n_bytes, OVERLAPPED *overlapped) {
static bool do_read(HANDLE *f, char *buf, size_t buf_size, size_t n_bytes, OVERLAPPED *overlapped) {
size_t to_read = buf_size;
if (n_bytes && to_read > n_bytes) {
to_read = n_bytes;

View file

@ -77,9 +77,7 @@ static char *showfile(char *res, const int nth, const char *fpath, const char *n
res = rz_str_appendf(res, "%s\n", nn);
} else if (printfmt == 'e') {
const char *eDIR = "📁";
const char *eLNK = "📎";
const char *eIMG = "🌅";
const char *eUID = "🔼";
const char *eHID = "👀";
const char *eANY = " ";
// --
@ -88,8 +86,10 @@ static char *showfile(char *res, const int nth, const char *fpath, const char *n
icon = eDIR;
#if __UNIX__
} else if ((sb.st_mode & S_IFMT) == S_IFLNK) {
const char *eLNK = "📎";
icon = eLNK;
} else if (sb.st_mode & S_ISUID) {
const char *eUID = "🔼";
icon = eUID;
#endif
} else if (rz_str_casestr(nn, ".jpg") || rz_str_casestr(nn, ".png") || rz_str_casestr(nn, ".gif")) {

View file

@ -14,17 +14,17 @@ static struct {
ut32 myers;
ut32 levenstein;
} tests[] = {
R("", "zzz", 3.0, 3.0),
R("meow", "", 4.0, 4.0),
R("a", "b", 2.0, 1.0),
R("aaa", "aaa", 0.0, 0.0),
R("aaaaa", "aabaa", 2.0, 1.0),
R("aaaa", "aabaa", 1.0, 1.0),
R("aaba", "babca", 3.0, 2.0),
R("foo", "foobar", 3.0, 3.0),
R("wallaby", "wallet", 5.0, 3.0),
R("identity", "identity", 0.0, 0.0),
{ NULL, NULL, 0.0, 0.0 }
R("", "zzz", 3, 3),
R("meow", "", 4, 4),
R("a", "b", 2, 1),
R("aaa", "aaa", 0, 0),
R("aaaaa", "aabaa", 2, 1),
R("aaaa", "aabaa", 1, 1),
R("aaba", "babca", 3, 2),
R("foo", "foobar", 3, 3),
R("wallaby", "wallet", 5, 3),
R("identity", "identity", 0, 0),
{ NULL, NULL, 0, 0 }
};
bool test_rz_diff_distances(void) {

View file

@ -28,14 +28,14 @@ bool test_rz_event(void) {
RzEventCallbackHandle handle_all = rz_event_hook(ev, RZ_EVENT_ALL, callback_test, &acc_all);
RzEventCallbackHandle handle_specific = rz_event_hook(ev, RZ_EVENT_META_SET, callback_test, &acc_specific);
rz_event_send(ev, RZ_EVENT_META_DEL, (void *)0x4242);
rz_event_send(ev, RZ_EVENT_META_DEL, (void *)(size_t)0x4242);
mu_assert_eq(acc_all.count, 1, "all count after event");
mu_assert_eq(acc_all.last_type, RZ_EVENT_META_DEL, "all type after event");
mu_assert_ptreq(acc_all.last_data, (void *)0x4242, "all type after event");
mu_assert_eq(acc_specific.count, 0, "specific count after other event");
rz_event_send(ev, RZ_EVENT_META_SET, (void *)0xdeadbeef);
rz_event_send(ev, RZ_EVENT_META_SET, (void *)(size_t)0xdeadbeef);
mu_assert_eq(acc_all.count, 2, "all count after event");
mu_assert_eq(acc_all.last_type, RZ_EVENT_META_SET, "all type after event");
@ -46,7 +46,7 @@ bool test_rz_event(void) {
mu_assert_ptreq(acc_specific.last_data, (void *)0xdeadbeef, "specific type after event");
rz_event_unhook(ev, handle_all);
rz_event_send(ev, RZ_EVENT_META_SET, (void *)0xc0ffee);
rz_event_send(ev, RZ_EVENT_META_SET, (void *)(size_t)0xc0ffee);
mu_assert_eq(acc_all.count, 2, "all count after event after being removed");
mu_assert_eq(acc_all.last_type, RZ_EVENT_META_SET, "all type after event after being removed");
@ -57,7 +57,7 @@ bool test_rz_event(void) {
mu_assert_ptreq(acc_specific.last_data, (void *)0xc0ffee, "specific type after event");
rz_event_unhook(ev, handle_specific);
rz_event_send(ev, RZ_EVENT_META_SET, (void *)0xc0ffee);
rz_event_send(ev, RZ_EVENT_META_SET, (void *)(size_t)0xc0ffee);
mu_assert_eq(acc_specific.count, 2, "specific count after event after being removed");
mu_assert_eq(acc_specific.last_type, RZ_EVENT_META_SET, "specific type after event after being removed");