aboutsummaryrefslogtreecommitdiffstats
path: root/src
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
commit3a92aa17478c901b1704fb935723783b11f193e7 (patch)
tree75cd382c180f31e56eafdaaa077c8ec9a89be361 /src
parent62388ceda61d89a9a58c5ba6181150912f67b93a (diff)
downloadmpd-3a92aa17478c901b1704fb935723783b11f193e7.tar.gz
mpd-3a92aa17478c901b1704fb935723783b11f193e7.tar.xz
mpd-3a92aa17478c901b1704fb935723783b11f193e7.zip
wreadln: use memcpy() for both cases
Use memcpy() even when the cursor is at the end. It copies only the trailing null terminator in this case. The constant "length" is declared here in preparation for the "wide character" patches.
Diffstat (limited to 'src')
-rw-r--r--src/wreadln.c17
1 files changed, 6 insertions, 11 deletions
diff --git a/src/wreadln.c b/src/wreadln.c
index 0bfc41408..5d019d900 100644
--- a/src/wreadln.c
+++ b/src/wreadln.c
@@ -120,17 +120,12 @@ static inline void drawline(const struct wreadln *wr)
static void
wreadln_insert_byte(struct wreadln *wr, gint key)
{
- if (strlen(wr->line + wr->cursor)) { /* if the cursor is */
- /* not at the last pos */
- gsize rest = strlen(wr->line + wr->cursor) + 1;
-
- memmove(wr->line + wr->cursor + 1,
- wr->line + wr->cursor, rest);
- wr->line[wr->cursor] = key;
- } else {
- wr->line[wr->cursor + 1] = 0;
- wr->line[wr->cursor] = key;
- }
+ size_t rest = strlen(wr->line + wr->cursor) + 1;
+ const size_t length = 1;
+
+ memmove(wr->line + wr->cursor + length,
+ wr->line + wr->cursor, rest);
+ wr->line[wr->cursor] = key;
cursor_move_right(wr);
}