Fix rz_bv_as_hex_string() for big 0
This was printing `0x` instead of `0x0` for big vectors when padding was disabled.
This commit is contained in:
parent
63616b76aa
commit
9401c9d67e
2 changed files with 13 additions and 2 deletions
|
|
@ -133,7 +133,7 @@ RZ_API RZ_OWN char *rz_bv_as_hex_string(RZ_NONNULL RzBitVector *bv, bool pad) {
|
|||
str[j++] = hex[high];
|
||||
pad = true; // pad means "print all" from now on
|
||||
}
|
||||
if (pad || low) {
|
||||
if (pad || low || i == bv->_elem_len - 1) {
|
||||
str[j++] = hex[low];
|
||||
pad = true; // pad means "print all" from now on
|
||||
}
|
||||
|
|
|
|||
|
|
@ -724,6 +724,12 @@ bool test_rz_bv_as_hex_string(void) {
|
|||
mu_assert_streq_free(s, "0x0000032a", "string hex value of bv");
|
||||
s = rz_bv_as_hex_string(bv, false);
|
||||
mu_assert_streq_free(s, "0x32a", "string hex value of bv");
|
||||
|
||||
rz_bv_set_from_ut64(bv, 0x0);
|
||||
s = rz_bv_as_hex_string(bv, true);
|
||||
mu_assert_streq_free(s, "0x00000000", "string hex value of bv");
|
||||
s = rz_bv_as_hex_string(bv, false);
|
||||
mu_assert_streq_free(s, "0x0", "string hex value of bv");
|
||||
rz_bv_free(bv);
|
||||
|
||||
// big
|
||||
|
|
@ -738,12 +744,17 @@ bool test_rz_bv_as_hex_string(void) {
|
|||
mu_assert_streq_free(s, "0x64", "string hex value of bv");
|
||||
|
||||
rz_bv_set(bv, 16, true);
|
||||
|
||||
s = rz_bv_as_hex_string(bv, true);
|
||||
mu_assert_streq_free(s, "0x00000000000000000000000000010064", "string hex value of bv");
|
||||
s = rz_bv_as_hex_string(bv, false);
|
||||
mu_assert_streq_free(s, "0x10064", "string hex value of bv");
|
||||
|
||||
rz_bv_set_from_ut64(bv, 0x0);
|
||||
s = rz_bv_as_hex_string(bv, true);
|
||||
mu_assert_streq_free(s, "0x00000000000000000000000000000000", "string hex value of bv");
|
||||
s = rz_bv_as_hex_string(bv, false);
|
||||
mu_assert_streq_free(s, "0x0", "string hex value of bv");
|
||||
|
||||
rz_bv_free(bv);
|
||||
mu_end;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue