Fix div by zero and help for $fl

This commit is contained in:
pancake 2016-12-19 04:27:13 +01:00
parent 2c5400e03e
commit 521458908b
2 changed files with 4 additions and 3 deletions

View File

@ -463,7 +463,7 @@ static int cmd_help(void *data, const char *input) {
"$b", "", "block size",
"$B", "", "base address (aligned lowest map address)",
"$f", "", "jump fail address (e.g. jz 0x10 => next instruction)",
"$fl", "", "flag length (size) at current address (fla; pD $l @ entry0)"
"$fl", "", "flag length (size) at current address (fla; pD $l @ entry0)",
"$F", "", "current function size",
"$FB", "", "begin of function",
"$Fb", "", "address of the current basic block",

View File

@ -16,7 +16,7 @@ static double get_px(ut8 x, const ut8 *data, ut64 size) {
count++;
}
}
return (double) count / size;
return size > 0? (double) count / size: 0;
}
R_API double r_hash_entropy(const ut8 *data, ut64 size) {
@ -24,8 +24,9 @@ R_API double r_hash_entropy(const ut8 *data, ut64 size) {
double h = 0, px, log2 = log (2.0);
for (x = 0; x < 256; x++) {
px = get_px (x, data, size);
if (px > 0)
if (px > 0) {
h += -px * (log (px) / log2);
}
}
return h;
}