Skip to content

Commit bc5c65b

Browse files
authored
extend size of address when file is larger than 4GB (pixel#72)
* extend size of address when file is larger than 4GB * changes requested in review (pixel#72)
1 parent 3f0d6ad commit bc5c65b

4 files changed

Lines changed: 40 additions & 3 deletions

File tree

display.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ int computeLineSize(void) { return computeCursorXPos(lineLength - 1, 0) + 1; }
8484
int computeCursorXCurrentPos(void) { return computeCursorXPos(cursor, hexOrAscii); }
8585
int computeCursorXPos(int cursor, int hexOrAscii)
8686
{
87-
int r = 11;
87+
int r = nAddrDigits + 3;
8888
int x = cursor % lineLength;
8989
int h = (hexOrAscii ? x : lineLength - 1);
9090

@@ -162,6 +162,13 @@ void exitCurses(void)
162162
endwin();
163163
}
164164

165+
static void printaddr(uint64_t addr)
166+
{
167+
char templ[7]; // maximum string is "%016lX", which is 6 chars + 1 null byte
168+
sprintf(templ,"%%0%dlX", nAddrDigits);
169+
PRINTW((templ, addr));
170+
}
171+
165172
void display(void)
166173
{
167174
long long fsize;
@@ -176,7 +183,7 @@ void display(void)
176183
move(i / lineLength, 0);
177184
for (j = 0; j < colsUsed; j++) printw(" "); /* cleanup the line */
178185
move(i / lineLength, 0);
179-
PRINTW(("%08lX", (int) (base + i)));
186+
printaddr(base+i);
180187
}
181188

182189
attrset(NORMAL);
@@ -201,7 +208,8 @@ void displayLine(int offset, int max)
201208
#ifdef HAVE_COLORS
202209
mark_color = COLOR_PAIR(4) | A_BOLD;
203210
#endif
204-
PRINTW(("%08lX ", (int) (base + offset)));
211+
printaddr(base + offset);
212+
PRINTW((" "));
205213
for (i = offset; i < offset + lineLength; i++) {
206214
if (i > offset) MAXATTRPRINTW(bufferAttr[i] & MARKED, (((i - offset) % blocSize) ? " " : " "));
207215
if (i < max) {

file.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,26 @@
1616
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.*/
1717
#include "hexedit.h"
1818

19+
20+
// Compute number of hex-digits needed to display an address.
21+
// We only increase this by full bytes (2 digits).
22+
// Because the input is uint64_t, the maximum result is 16 (64bit = 16*4bit).
23+
int compute_nDigits(uint64_t maxAddr)
24+
{
25+
int digits = 0;
26+
while (maxAddr) {
27+
digits+=2;
28+
maxAddr >>= 8;
29+
}
30+
31+
if (digits==0) {
32+
return 2;
33+
}
34+
35+
return digits;
36+
}
37+
38+
1939
void openFile(void)
2040
{
2141
struct stat st;
@@ -53,6 +73,13 @@ void openFile(void)
5373
fileSize = 0;
5474
}
5575
biggestLoc = fileSize;
76+
77+
nAddrDigits = compute_nDigits(biggestLoc);
78+
79+
// use at least 8 digits (4 byte addresses)
80+
if (nAddrDigits < 8) {
81+
nAddrDigits = 8;
82+
}
5683
}
5784

5885
void readFile(void)

hexedit.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ INT base, oldbase;
2626
int normalSpaces, cursor, cursorOffset, hexOrAscii;
2727
int cursor, blocSize, lineLength, colsUsed, page;
2828
int fd, nbBytes, oldcursor, oldattr, oldcursorOffset;
29+
int nAddrDigits;
2930
int sizeCopyBuffer, *bufferAttr;
3031
char *progName, *fileName, *baseName;
3132
unsigned char *buffer, *copyBuffer;

hexedit.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ extern INT base, oldbase;
9797
extern int normalSpaces, cursor, cursorOffset, hexOrAscii;
9898
extern int cursor, blocSize, lineLength, colsUsed, page;
9999
extern int isReadOnly, fd, nbBytes, oldcursor, oldattr, oldcursorOffset;
100+
extern int nAddrDigits;
100101
extern int sizeCopyBuffer, *bufferAttr;
101102
extern char *progName, *fileName, *baseName;
102103
extern unsigned char *buffer, *copyBuffer;

0 commit comments

Comments
 (0)