Fix undefined behaviour in pd with emustr

This commit is contained in:
pancake 2017-01-23 22:42:27 +01:00
parent bbed5daef1
commit d619c6039f
3 changed files with 16 additions and 11 deletions
libr
cons
core
include

@ -1196,15 +1196,19 @@ R_API void r_cons_highlight (const char *word) {
}
}
R_API char *r_cons_lastline () {
char *b = I.buffer+I.buffer_len;
while (b >I.buffer) {
R_API char *r_cons_lastline (int *len) {
char *b = I.buffer + I.buffer_len;
while (b > I.buffer) {
if (*b == '\n') {
b++;
break;
}
b--;
}
if (len) {
int delta = b - I.buffer;
*len = I.buffer_len - delta;
}
return b;
}

@ -2397,9 +2397,9 @@ static void ds_print_core_vmode(RDisasmState *ds) {
static void ds_align_comment(RDisasmState *ds) {
const int cmtcol = ds->cmtcol;
if (ds->show_comment_right_default) {
char *ll = r_cons_lastline ();
int cstrlen = 0;
char *ll = r_cons_lastline (&cstrlen);
if (ll) {
int cstrlen = strlen (ll);
int cols, ansilen = r_str_ansi_len (ll);
int utf8len = r_utf8_strlen ((const ut8*)ll);
int cells = utf8len - (cstrlen - ansilen);
@ -2766,8 +2766,8 @@ static void ds_print_relocs(RDisasmState *ds) {
if (rel) {
const int cmtcol = ds->cmtcol;
char *ll = r_cons_lastline ();
int cstrlen = strlen (ll);
int cstrlen = 0;
char *ll = r_cons_lastline (&cstrlen);
int ansilen = r_str_ansi_len (ll);
int utf8len = r_utf8_strlen ((const ut8*)ll);
int cells = utf8len - (cstrlen - ansilen);
@ -2941,11 +2941,12 @@ static void print_fcn_arg(RCore *core, const char *type, const char *name,
static void delete_last_comment(RDisasmState *ds) {
if (ds->show_comment_right_default) {
char *ll = r_cons_lastline ();
int len = 0;
char *ll = r_cons_lastline (&len);
if (ll) {
char * begin = strstr (ll, "; ");
char *begin = strnstr (ll, "; ", len);
if (begin) {
int cstrlen = strlen (ll);
const int cstrlen = strlen (ll);
r_cons_drop (cstrlen - (int)(begin - ll));
}
}

@ -427,7 +427,7 @@ R_API void r_cons_canvas_fill(RConsCanvas *c, int x, int y, int w, int h, char c
R_API RCons *r_cons_new (void);
R_API RCons *r_cons_singleton (void);
R_API RCons *r_cons_free (void);
R_API char *r_cons_lastline (void);
R_API char *r_cons_lastline (int *size);
typedef void (*RConsBreak)(void *);
R_API void r_cons_break_end(void);