mirror of
https://github.com/samba-team/samba.git
synced 2025-02-02 09:47:23 +03:00
regedit: Handle zero-length buffers better with hexedit.
Reviewed-by: Andreas Schneider <asn@samba.org> Reviewed-by: Michael Adam <obnox@samba.org>
This commit is contained in:
parent
ad15a83357
commit
8ea38ce970
@ -1027,8 +1027,10 @@ static WERROR handle_editor_input(struct edit_dialog *edit,
|
||||
"Enter new size");
|
||||
if (n) {
|
||||
newlen = strtoul(n, NULL, 10);
|
||||
edit->section = IN_DATA;
|
||||
hexedit_resize_buffer(edit->buf, newlen);
|
||||
hexedit_refresh(edit->buf);
|
||||
hexedit_set_cursor(edit->buf);
|
||||
talloc_free(n);
|
||||
}
|
||||
} else if (selection == DIALOG_CANCEL) {
|
||||
|
@ -93,8 +93,12 @@ static size_t bytes_per_screen(WINDOW *win)
|
||||
void hexedit_set_cursor(struct hexedit *buf)
|
||||
{
|
||||
werase(buf->status_line);
|
||||
wprintw(buf->status_line, "Len:%lu Off:%lu Val:0x%X", buf->len,
|
||||
buf->cursor_offset, buf->data[buf->cursor_offset]);
|
||||
if (buf->len) {
|
||||
wprintw(buf->status_line, "Len:%lu Off:%lu Val:0x%X", buf->len,
|
||||
buf->cursor_offset, buf->data[buf->cursor_offset]);
|
||||
} else {
|
||||
wprintw(buf->status_line, "Len:%lu (empty)", buf->len);
|
||||
}
|
||||
wmove(buf->win, buf->cursor_y, buf->cursor_x);
|
||||
wcursyncup(buf->win);
|
||||
wsyncup(buf->win);
|
||||
@ -108,6 +112,10 @@ void hexedit_refresh(struct hexedit *buf)
|
||||
size_t off;
|
||||
|
||||
werase(buf->win);
|
||||
if (buf->len == 0) {
|
||||
mvwprintw(buf->win, 0, 0, "%08X", 0);
|
||||
return;
|
||||
}
|
||||
|
||||
end = buf->offset + bytes_per_screen(buf->win);
|
||||
if (end > buf->len) {
|
||||
@ -294,6 +302,9 @@ static void cursor_right(struct hexedit *buf)
|
||||
{
|
||||
int new_x = buf->cursor_x + 1;
|
||||
|
||||
if (buf->len == 0) {
|
||||
return;
|
||||
}
|
||||
if (new_x == ASCII_COL_END) {
|
||||
return;
|
||||
}
|
||||
@ -335,6 +346,10 @@ static void do_edit(struct hexedit *buf, int c)
|
||||
{
|
||||
uint8_t *byte;
|
||||
|
||||
if (buf->len == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
byte = buf->data + buf->cursor_offset;
|
||||
|
||||
if (buf->cursor_x >= ASCII_COL) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user