aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--degesch.c24
1 files changed, 11 insertions, 13 deletions
diff --git a/degesch.c b/degesch.c
index 54f523e..9f17678 100644
--- a/degesch.c
+++ b/degesch.c
@@ -5589,10 +5589,10 @@ on_editline_complete (EditLine *editline, int key)
unsigned char result = CC_REFRESH_BEEP;
// First prepare what Readline would have normally done for us...
- const LineInfo *info = el_line (editline);
- int len = info->lastchar - info->buffer;
- int point = info->cursor - info->buffer;
- char *copy = xstrndup (info->buffer, len);
+ const LineInfo *info_mb = el_line (editline);
+ int len = info_mb->lastchar - info_mb->buffer;
+ int point = info_mb->cursor - info_mb->buffer;
+ char *copy = xstrndup (info_mb->buffer, len);
// XXX: possibly incorrect wrt. shift state encodings
int el_start = point, el_end = point;
@@ -5652,17 +5652,15 @@ on_editline_return (EditLine *editline, int key)
history_w (self->current->history, &ev, H_ENTER, line);
print_debug ("history: %d %ls", ev.num, ev.str);
}
-
- // Convert it to multibyte to reflect the Readline interface
- size_t needed = wcstombs (NULL, line, 0) + 1;
- char converted[needed];
- if (!needed || wcstombs (converted, line, needed) == (size_t) -1)
- print_error ("encoding conversion failed");
- else
- process_input (g_ctx, converted);
-
free (line);
+ // process_input() expects a multibyte string
+ const LineInfo *info_mb = el_line (editline);
+ char copy[info_mb->lastchar - info_mb->buffer + 1];
+ memcpy (copy, info_mb->buffer, sizeof copy - 1);
+ copy[sizeof copy - 1] = '\0';
+ process_input (g_ctx, copy);
+
el_cursor (editline, len - point);
el_wdeletestr (editline, len);
return CC_REFRESH;