From: Max Kellermann Date: Mon, 6 Oct 2008 12:55:31 +0000 (+0200) Subject: wreadln: use memcpy() for both cases X-Git-Tag: v0.12_alpha1~56 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=3a92aa17478c901b1704fb935723783b11f193e7;p=ncmpc.git 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. --- diff --git a/src/wreadln.c b/src/wreadln.c index 0bfc414..5d019d9 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); }