Fix regressions in pf parsing and enhance error reporting

This commit is contained in:
pancake 2016-12-14 16:09:45 +01:00
parent 0053dfefd8
commit c70c8f78ee
2 changed files with 10 additions and 7 deletions

View File

@ -29,8 +29,8 @@ static void print_meta_offset(RCore *core, ut64 offset) {
if (line >= 2)
line -= 2;
if (r_file_exists (file)) {
for (i = 0; i<5; i++) {
char *row = r_file_slurp_line (file, line+i, 0);
for (i = 0; i < 5; i++) {
char *row = r_file_slurp_line (file, line + i, 0);
if (row) {
r_cons_printf ("%c %.3x %s\n", line+i == line_old ? '>' : ' ', line+i, row);
free (row);
@ -488,6 +488,9 @@ static int cmd_meta_hsdmf(RCore *core, const char *input) {
if (r < 0) {
n = -1;
}
} else {
eprintf ("Usage: Cf [size] [pf-format-string]\n");
break;
}
} else if (type == 's') { //Cs
char tmp[256] = {0};

View File

@ -1140,12 +1140,12 @@ static void r_print_format_num (const RPrint *p, int endian, int mode, const cha
// XXX: this is somewhat incomplete. must be updated to handle all format chars
int r_print_format_struct_size(const char *f, RPrint *p, int mode) {
char *o, *end, *args, *fmt;
char *end, *args, *fmt;
int size = 0, tabsize = 0, i, idx = 0, biggest = 0, fmt_len = 0;
if (!f) {
return -1;
}
o = strdup (f);
char *o = strdup (f);
if (!o) {
return -1;
}
@ -1316,7 +1316,7 @@ int r_print_format_struct_size(const char *f, RPrint *p, int mode) {
eprintf ("Invalid n format.\n");
free (o);
free (args);
return -1;
return -2;
}
i++;
break;
@ -1552,8 +1552,8 @@ R_API int r_print_format(RPrint *p, ut64 seek, const ut8* b, const int len,
} else {
size = -1;
}
int fs = r_print_format_struct_size(arg, p, 0);
if (fs == -1) {
int fs = r_print_format_struct_size (arg, p, 0);
if (fs == -2) {
i = -1;
goto beach;
}