From 521458908b0aef72ca9bc471ace757942fcce601 Mon Sep 17 00:00:00 2001 From: pancake Date: Mon, 19 Dec 2016 04:27:13 +0100 Subject: [PATCH] Fix div by zero and help for $fl --- libr/core/cmd_help.c | 2 +- libr/hash/entropy.c | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/libr/core/cmd_help.c b/libr/core/cmd_help.c index c76439b6c0..8cf82101c8 100644 --- a/libr/core/cmd_help.c +++ b/libr/core/cmd_help.c @@ -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", diff --git a/libr/hash/entropy.c b/libr/hash/entropy.c index d38ec7703b..00007a0e38 100644 --- a/libr/hash/entropy.c +++ b/libr/hash/entropy.c @@ -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; }