Skip to content

Commit

Permalink
changes requested in review (#72)
Browse files Browse the repository at this point in the history
  • Loading branch information
farindk committed Jul 30, 2024
1 parent 57afba0 commit fd133e1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
2 changes: 1 addition & 1 deletion display.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ void exitCurses(void)

static void printaddr(uint64_t addr)
{
char templ[7];
char templ[7]; // maximum string is "%016lX", which is 6 chars + 1 null byte
sprintf(templ,"%%0%dlX", nAddrDigits);
PRINTW((templ, addr));
}
Expand Down
33 changes: 24 additions & 9 deletions file.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,26 @@
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.*/
#include "hexedit.h"


// Compute number of hex-digits needed to display an address.
// We only increase this by full bytes (2 digits).
// Because the input is uint64_t, the maximum result is 16 (64bit = 16*4bit).
int compute_nDigits(uint64_t maxAddr)
{
int digits = 0;
while (maxAddr) {
digits+=2;
maxAddr >>= 8;
}

if (digits==0) {
return 2;
}

return digits;
}


void openFile(void)
{
struct stat st;
Expand Down Expand Up @@ -54,16 +74,11 @@ void openFile(void)
}
biggestLoc = fileSize;

// compute number of digits for address
nAddrDigits = compute_nDigits(biggestLoc);

nAddrDigits=8;
off_t maxAddr = biggestLoc;
if (maxAddr > 0xFFFFFFFF) {
maxAddr >>= 32;
while (maxAddr) {
nAddrDigits+=2;
maxAddr >>= 8;
}
// use at least 8 digits (4 byte addresses)
if (nAddrDigits < 8) {
nAddrDigits = 8;
}
}

Expand Down

0 comments on commit fd133e1

Please sign in to comment.