summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 62388ce)
raw | patch | inline | side by side (parent: 62388ce)
author | Max Kellermann <max@duempel.org> | |
Mon, 6 Oct 2008 12:55:31 +0000 (14:55 +0200) | ||
committer | Max Kellermann <max@duempel.org> | |
Mon, 6 Oct 2008 12:55:31 +0000 (14:55 +0200) |
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.
trailing null terminator in this case.
The constant "length" is declared here in preparation for the "wide
character" patches.
src/wreadln.c | patch | blob | history |
diff --git a/src/wreadln.c b/src/wreadln.c
index 0bfc414086a7ac541b990d776492a74f146576c0..5d019d9003d3438b1287141082fa380349dbf167 100644 (file)
--- a/src/wreadln.c
+++ b/src/wreadln.c
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);
}