Fix warnings by using more r_str_ncpy
* Fix wrong logic in visual_search When the string to be searched is wrapped in " ", you want to remove the first and last quotes and look only for the internal string. * Increase size to prevent string truncation (and fix compiler warning) * Fix "destination unchanged after copying no bytes" warning * Move msp430_register_names where it belongs to * Fix Wstringop-truncation warning
This commit is contained in:
parent
d95f8ac768
commit
738bc9cb19
|
@ -59,7 +59,7 @@ RAnalReilArg *reil_pop_arg(RAnalEsil *esil) {
|
|||
for (i = 0; i < len; i++) {
|
||||
if (buf[i] == ':') {
|
||||
tmp_buf[j] = '\0';
|
||||
strncpy (op->name, tmp_buf, sizeof (op->name) - 1);
|
||||
r_str_ncpy (op->name, tmp_buf, sizeof (op->name));
|
||||
memset (tmp_buf, 0, sizeof (tmp_buf));
|
||||
j = 0;
|
||||
flag = 1;
|
||||
|
@ -76,8 +76,8 @@ RAnalReilArg *reil_pop_arg(RAnalEsil *esil) {
|
|||
|
||||
// If we have not encountered a ':' we don't know the size yet.
|
||||
if (!flag) {
|
||||
strncpy(op->name, tmp_buf, sizeof(op->name) - 1);
|
||||
op->type = reil_get_arg_type(esil, op->name);
|
||||
r_str_ncpy (op->name, tmp_buf, sizeof (op->name));
|
||||
op->type = reil_get_arg_type (esil, op->name);
|
||||
if (op->type == ARG_REG) {
|
||||
op->size = esil_internal_sizeof_reg(esil, op->name);
|
||||
} else if (op->type == ARG_CONST) {
|
||||
|
|
|
@ -665,8 +665,7 @@ static st32 getlistmask(char *input) {
|
|||
for (i = 0; input[i] != ',' && input[i] != '\0'; i++) {
|
||||
;
|
||||
}
|
||||
strncpy (temp, input, i);
|
||||
temp[i] = 0;
|
||||
r_str_ncpy (temp, input, i + 1);
|
||||
|
||||
input += i;
|
||||
if (*input != '\0') {
|
||||
|
|
|
@ -3,6 +3,25 @@
|
|||
|
||||
#include "msp430_disas.h"
|
||||
|
||||
static const char *msp430_register_names[] = {
|
||||
"pc",
|
||||
"sp",
|
||||
"sr",
|
||||
"cg",
|
||||
"r4",
|
||||
"r5",
|
||||
"r6",
|
||||
"r7",
|
||||
"r8",
|
||||
"r9",
|
||||
"r10",
|
||||
"r11",
|
||||
"r12",
|
||||
"r13",
|
||||
"r14",
|
||||
"r15",
|
||||
};
|
||||
|
||||
static const char *two_op_instrs[] = {
|
||||
[MSP430_MOV] = "mov",
|
||||
[MSP430_ADD] = "add",
|
||||
|
|
|
@ -72,25 +72,6 @@ enum msp430_registers {
|
|||
MSP430_R15,
|
||||
};
|
||||
|
||||
static const char *msp430_register_names[] = {
|
||||
"pc",
|
||||
"sp",
|
||||
"sr",
|
||||
"cg",
|
||||
"r4",
|
||||
"r5",
|
||||
"r6",
|
||||
"r7",
|
||||
"r8",
|
||||
"r9",
|
||||
"r10",
|
||||
"r11",
|
||||
"r12",
|
||||
"r13",
|
||||
"r14",
|
||||
"r15",
|
||||
};
|
||||
|
||||
struct msp430_cmd {
|
||||
ut8 type;
|
||||
ut8 opcode;
|
||||
|
|
|
@ -771,23 +771,22 @@ static void findPrevWord(RCore *core) {
|
|||
static void visual_search(RCore *core) {
|
||||
const ut8 *p;
|
||||
int len, d = core->print->cur;
|
||||
char str[128], buf[258];
|
||||
char str[128], buf[sizeof (str) * 2 + 1];
|
||||
|
||||
r_line_set_prompt ("search byte/string in block: ");
|
||||
r_cons_fgets (str, sizeof (str), 0, NULL);
|
||||
len = r_hex_str2bin (str, (ut8 *) buf);
|
||||
if (*str == '"') {
|
||||
char *e = strncpy (buf + 1, str + 1, sizeof (buf) - 1);
|
||||
if (e) {
|
||||
e--;
|
||||
if (*e == '"') {
|
||||
*e = 0;
|
||||
}
|
||||
}
|
||||
r_str_ncpy (buf, str + 1, sizeof (buf));
|
||||
len = strlen (buf);
|
||||
char *e = buf + len - 1;
|
||||
if (e > buf && *e == '"') {
|
||||
*e = 0;
|
||||
len--;
|
||||
}
|
||||
} else if (len < 1) {
|
||||
strncpy (buf, str, sizeof (buf) - 1);
|
||||
len = strlen (str);
|
||||
r_str_ncpy (buf, str, sizeof (buf));
|
||||
len = strlen (buf);
|
||||
}
|
||||
p = r_mem_mem (core->block + d, core->blocksize - d,
|
||||
(const ut8 *) buf, len);
|
||||
|
|
|
@ -219,7 +219,7 @@ R_API int r_debug_reg_list(RDebug *dbg, int type, int size, int rad, const char
|
|||
case 2:
|
||||
{
|
||||
int len, highlight = use_color && pr && pr->cur_enabled && itmidx == pr->cur;
|
||||
char *str, whites[32], content[128];
|
||||
char *str, whites[32], content[300];
|
||||
const char *a = "", *b = "";
|
||||
if (highlight) {
|
||||
a = Color_INVERT;
|
||||
|
|
|
@ -118,7 +118,7 @@ R_API int r_fs_shell_prompt(RFSShell* shell, RFS* fs, const char* root) {
|
|||
eprintf ("%s\n", path);
|
||||
} else if (!memcmp (buf, "cd ", 3)) {
|
||||
char opath[PROMPT_PATH_BUFSIZE];
|
||||
strncpy (opath, path, sizeof (opath) - 1);
|
||||
r_str_ncpy (opath, path, sizeof (opath));
|
||||
input = buf + 3;
|
||||
while (*input == ' ') {
|
||||
input++;
|
||||
|
|
|
@ -39,10 +39,10 @@ R_API bool r_str_range_in(const char *r, ut64 addr);
|
|||
R_API int r_str_len_utf8(const char *s);
|
||||
R_API int r_str_len_utf8char(const char *s, int left);
|
||||
R_API void r_str_filter_zeroline(char *str, int len);
|
||||
R_API int r_str_utf8_codepoint (const char* s, int left);
|
||||
R_API bool r_str_char_fullwidth (const char* s, int left);
|
||||
R_API int r_str_utf8_codepoint(const char *s, int left);
|
||||
R_API bool r_str_char_fullwidth(const char *s, int left);
|
||||
R_API int r_str_write(int fd, const char *b);
|
||||
R_API void r_str_ncpy(char *dst, const char *src, int n);
|
||||
R_API void r_str_ncpy(char *dst, const char *src, size_t n);
|
||||
R_API void r_str_sanitize(char *c);
|
||||
R_API const char *r_str_casestr(const char *a, const char *b);
|
||||
R_API const char *r_str_firstbut(const char *s, char ch, const char *but);
|
||||
|
|
|
@ -744,8 +744,14 @@ R_API char *r_str_newf(const char *fmt, ...) {
|
|||
}
|
||||
|
||||
// Secure string copy with null terminator (like strlcpy or strscpy but ours
|
||||
R_API void r_str_ncpy(char *dst, const char *src, int n) {
|
||||
R_API void r_str_ncpy(char *dst, const char *src, size_t n) {
|
||||
int i;
|
||||
|
||||
// do not do anything if n is 0
|
||||
if (n == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
n--;
|
||||
for (i = 0; src[i] && n > 0; i++, n--) {
|
||||
dst[i] = src[i];
|
||||
|
|
Loading…
Reference in New Issue