aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2008-10-06 14:55:31 +0200
committerMax Kellermann <max@duempel.org>2008-10-06 14:55:31 +0200
commit62388ceda61d89a9a58c5ba6181150912f67b93a (patch)
tree0924bcecf8444d7461b9b56969e72a130175166e
parent147e3849ba1f451d195e33f1eb35ab5a7b86f035 (diff)
downloadmpd-62388ceda61d89a9a58c5ba6181150912f67b93a.tar.gz
mpd-62388ceda61d89a9a58c5ba6181150912f67b93a.tar.xz
mpd-62388ceda61d89a9a58c5ba6181150912f67b93a.zip
wreadln: use memmove() instead of an temporary buffer
memmove() handles overlapping buffers well, we can use it to get room for the inserted character.
-rw-r--r--src/wreadln.c9
1 files changed, 2 insertions, 7 deletions
diff --git a/src/wreadln.c b/src/wreadln.c
index f10b8c23f..0bfc41408 100644
--- a/src/wreadln.c
+++ b/src/wreadln.c
@@ -122,16 +122,11 @@ wreadln_insert_byte(struct wreadln *wr, gint key)
{
if (strlen(wr->line + wr->cursor)) { /* if the cursor is */
/* not at the last pos */
- gchar *tmp = NULL;
gsize rest = strlen(wr->line + wr->cursor) + 1;
- tmp = g_malloc0(rest);
- g_strlcpy (tmp, wr->line + wr->cursor, rest);
+ memmove(wr->line + wr->cursor + 1,
+ wr->line + wr->cursor, rest);
wr->line[wr->cursor] = key;
- wr->line[wr->cursor + 1] = 0;
- g_strlcat(&wr->line[wr->cursor + 1], tmp, rest);
- g_free(tmp);
- cursor_move_right(wr);
} else {
wr->line[wr->cursor + 1] = 0;
wr->line[wr->cursor] = key;