summaryrefslogtreecommitdiff
path: root/source3/utils/regedit_hexedit.c
diff options
context:
space:
mode:
authorC. Davis <cd.rattan@gmail.com>2012-08-19 19:11:16 -0700
committerMichael Adam <obnox@samba.org>2013-04-29 13:07:54 +0200
commit8ea38ce970d7539c25d4da08065d6bfa999f3e96 (patch)
tree17d68242f17a8535bf4e3d6554e8cefd7cd882c9 /source3/utils/regedit_hexedit.c
parentad15a83357dccc9a41ade1642cca24a0b7de92df (diff)
downloadsamba-8ea38ce970d7539c25d4da08065d6bfa999f3e96.tar.gz
regedit: Handle zero-length buffers better with hexedit.
Reviewed-by: Andreas Schneider <asn@samba.org> Reviewed-by: Michael Adam <obnox@samba.org>
Diffstat (limited to 'source3/utils/regedit_hexedit.c')
-rw-r--r--source3/utils/regedit_hexedit.c19
1 files changed, 17 insertions, 2 deletions
diff --git a/source3/utils/regedit_hexedit.c b/source3/utils/regedit_hexedit.c
index e2864e3fae3..8f1c2c72f87 100644
--- a/source3/utils/regedit_hexedit.c
+++ b/source3/utils/regedit_hexedit.c
@@ -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) {