Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

extend size of address when file is larger than 4GB #72

Merged
merged 2 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions display.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ int computeLineSize(void) { return computeCursorXPos(lineLength - 1, 0) + 1; }
int computeCursorXCurrentPos(void) { return computeCursorXPos(cursor, hexOrAscii); }
int computeCursorXPos(int cursor, int hexOrAscii)
{
int r = 11;
int r = nAddrDigits + 3;
int x = cursor % lineLength;
int h = (hexOrAscii ? x : lineLength - 1);

Expand Down Expand Up @@ -162,6 +162,13 @@ void exitCurses(void)
endwin();
}

static void printaddr(uint64_t addr)
{
char templ[7];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

7 needs to be explained.
Afaik it is sizeof("%016lX") with 16 being the max nAddrDigits

sprintf(templ,"%%0%dlX", nAddrDigits);
PRINTW((templ, addr));
}

void display(void)
{
long long fsize;
Expand All @@ -176,7 +183,7 @@ void display(void)
move(i / lineLength, 0);
for (j = 0; j < colsUsed; j++) printw(" "); /* cleanup the line */
move(i / lineLength, 0);
PRINTW(("%08lX", (int) (base + i)));
printaddr(base+i);
}

attrset(NORMAL);
Expand All @@ -201,7 +208,8 @@ void displayLine(int offset, int max)
#ifdef HAVE_COLORS
mark_color = COLOR_PAIR(4) | A_BOLD;
#endif
PRINTW(("%08lX ", (int) (base + offset)));
printaddr(base + offset);
PRINTW((" "));
for (i = offset; i < offset + lineLength; i++) {
if (i > offset) MAXATTRPRINTW(bufferAttr[i] & MARKED, (((i - offset) % blocSize) ? " " : " "));
if (i < max) {
Expand Down
12 changes: 12 additions & 0 deletions file.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,18 @@ void openFile(void)
fileSize = 0;
}
biggestLoc = fileSize;

// compute number of digits for address
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest adding a comment somewhere explaining that nAddrDigits max is 16 (max size is 2**64 and a hex char is 2**4 wide)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you move this code to a function compute_nAddrDigits (or something alike)


nAddrDigits=8;
off_t maxAddr = biggestLoc;
if (maxAddr > 0xFFFFFFFF) {
maxAddr >>= 32;
while (maxAddr) {
nAddrDigits+=2;
maxAddr >>= 8;
}
}
}

void readFile(void)
Expand Down
1 change: 1 addition & 0 deletions hexedit.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ INT base, oldbase;
int normalSpaces, cursor, cursorOffset, hexOrAscii;
int cursor, blocSize, lineLength, colsUsed, page;
int fd, nbBytes, oldcursor, oldattr, oldcursorOffset;
int nAddrDigits;
int sizeCopyBuffer, *bufferAttr;
char *progName, *fileName, *baseName;
unsigned char *buffer, *copyBuffer;
Expand Down
1 change: 1 addition & 0 deletions hexedit.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ extern INT base, oldbase;
extern int normalSpaces, cursor, cursorOffset, hexOrAscii;
extern int cursor, blocSize, lineLength, colsUsed, page;
extern int isReadOnly, fd, nbBytes, oldcursor, oldattr, oldcursorOffset;
extern int nAddrDigits;
extern int sizeCopyBuffer, *bufferAttr;
extern char *progName, *fileName, *baseName;
extern unsigned char *buffer, *copyBuffer;
Expand Down