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

Bug hangs pressing F3 next time with filenames longer than 136 chars #30

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
9 changes: 9 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
september 2018:
- Now writes before of filename, file position and file size at status line because if filename is long,
user cannot view file position and file size
- fix clean filename at end of line after load with F3 when filename reach end of line
- fix input long filename (longer than 136 chars) with F3 for next time. It repeats long filename until bottom screen and hangs.
Only works CTRL+C. I think that is a bug in ncurses. My work around is to print the long filename (if is longer than 136 chars),
but you can't edit it. You can load it pressing the RETURN key
- fix copy & paste bytes unchanged between bytes changed. Paste leave bytes unchanged to 00

september 2017
- 1.4.2
- fix spelling errors in manpage
Expand Down
41 changes: 33 additions & 8 deletions display.c
Original file line number Diff line number Diff line change
Expand Up @@ -191,23 +191,30 @@ void display(void)
for (; i < page; i += lineLength) {
int j;
move(i / lineLength, 0);
for (j = 0; j < colsUsed; j++) printw(" "); /* cleanup the line */
clrtoeol();
move(i / lineLength, 0);
PRINTW(("%08lX", (int) (base + i)));
}

attrset(NORMAL);
move(LINES - 1, 0);
for (i = 0; i < colsUsed; i++) printw("-");
int szBuffer = 100;
char buffer[szBuffer];
int len = snprintf(buffer, szBuffer, "%08llX", base + i) - 8;
for (i = 0; i < colsUsed + len; i++) printw("-");
clrtoeol();
move(LINES - 1, 0);
if (isReadOnly) i = '%';
else if (edited) i = '*';
else i = '-';
printw("-%c%c %s --0x%llX", i, i, baseName, base + cursor);
printw("-%c%c --0x%llX", i, i, base + cursor);

if (MAX(fileSize, lastEditedLoc)) printw("/0x%llX", getfilesize());
printw("--%i%%", 100 * (base + cursor + getfilesize()/200) / getfilesize() );
if (mode == bySector) printw("--sector %lld", (base + cursor) / SECTOR_SIZE);

printw(" %s", baseName);

move(cursor / lineLength, computeCursorXCurrentPos());
}

Expand Down Expand Up @@ -240,6 +247,8 @@ void displayLine(int offset, int max)
else if (buffer[i] >= ' ' && buffer[i] < 127) ATTRPRINTW((cursor == i && hexOrAscii==1 ? mark_color : 0) | bufferAttr[i], ("%c", buffer[i]));
else ATTRPRINTW((cursor == i && hexOrAscii == 1 ? mark_color : 0) | bufferAttr[i], ("."));
}
PRINTW((" "));
clrtoeol();
}

void clr_line(int line) { move(line, 0); clrtoeol(); }
Expand Down Expand Up @@ -279,7 +288,7 @@ int displayMessageAndGetString(const char *msg, char **last, char *p, int p_size
int ret = TRUE;

displayOneLineMessage(msg);
ungetstr(*last);
ungetstr(*last, p_size);
echo();
getnstr(p, p_size - 1);
noecho();
Expand All @@ -292,11 +301,27 @@ int displayMessageAndGetString(const char *msg, char **last, char *p, int p_size
return ret;
}

void ungetstr(char *s)
void ungetstr(char *s, size_t p_size)
{
char *p;
if (s)
for (p = s + strlen(s) - 1; p >= s; p--) ungetch(*p);
wchar_t ws[p_size];
wchar_t *w;
bool nonASCII = false;

if (s) {
swprintf(ws, p_size, L"%hs", s);
int i;
for (i=0; i<wcslen(ws); i++) {
if (ws[i] > 127) nonASCII = true;
}
if ((wcslen(ws) < 137) && (!nonASCII)) {
for (w = ws + wcslen(ws) - 1; w >= ws; w--) {
if (unget_wch(*w) != OK) {
printf("unget_wch ERROR!");
break;
}
}
}
}
}

int get_number(INT *i)
Expand Down
17 changes: 16 additions & 1 deletion file.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,22 @@ int findFile(void)
{
char *p, tmp[BLOCK_SEARCH_SIZE];
p = lastFindFile ? strdup(lastFindFile) : NULL;
if (!displayMessageAndGetString("File name: ", &p, tmp, sizeof(tmp))) return FALSE;
if ((p != NULL) && (strlen(p) > 136)) {
char msg[4097];
snprintf(msg, 4096, "File name [%s]: ", p);
int center = page / lineLength / 2;
int lines = strlen(msg) / COLS;
if ((strlen(msg) > COLS) && (strlen(msg) % COLS)) lines++;
if ((strlen(msg) % COLS) > (int)(COLS * 0.8)) lines++;
if ((strlen(msg) % COLS) > (int)(COLS * 0.8) && (strlen(msg) < COLS)) lines++;
if (strlen(msg) == COLS) lines++;
for (int i = 2; i < lines + 1; i++) {
clr_line(center + i);
}
if (!displayMessageAndGetString(msg, &p, tmp, sizeof(tmp))) return FALSE;
} else {
if (!displayMessageAndGetString("File name: ", &p, tmp, sizeof(tmp))) return FALSE;
}
if (!is_file(tmp)) return FALSE;
FREE(lastFindFile); lastFindFile = fileName;
fileName = p;
Expand Down
1 change: 0 additions & 1 deletion hexedit.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.*/
#include "hexedit.h"


/*******************************************************************************/
/* Global variables */
/*******************************************************************************/
Expand Down
3 changes: 1 addition & 2 deletions hexedit.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
#include <sys/mount.h> /* for BLKGETSIZE */
#endif


#define INT off_t

/*******************************************************************************/
Expand Down Expand Up @@ -158,7 +157,7 @@ void displayOneLineMessage(const char *msg);
void displayTwoLineMessage(const char *msg1, const char *msg2);
void displayMessageAndWaitForKey(const char *msg);
int displayMessageAndGetString(const char *msg, char **last, char *p, int p_size);
void ungetstr(char *s);
void ungetstr(char *s, size_t p_size);
int get_number(INT *i);


Expand Down
2 changes: 1 addition & 1 deletion interact.c
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ static void goto_char(void)
INT i;

displayOneLineMessage("New position ? ");
ungetstr("0x");
ungetstr("0x", BLOCK_SEARCH_SIZE);
if (!get_number(&i) || !set_cursor(i)) displayMessageAndWaitForKey("Invalid position!");
}

Expand Down