diff options
author | Jérémie Courrèges-Anglas <jca@wxcvbn.org> | 2014-03-04 03:02:23 +0100 |
---|---|---|
committer | Jérémie Courrèges-Anglas <jca@wxcvbn.org> | 2014-03-04 03:02:23 +0100 |
commit | d4884d7643e30ceaf7e9093d2fc41972971786f2 (patch) | |
tree | 2550fc18566882e38ebd3595fe11a2eb578fd6d1 | |
parent | d714a5a2776c0afc6397a9e89adc328eaa75ca8f (diff) | |
download | ratpoison-d4884d7643e30ceaf7e9093d2fc41972971786f2.zip |
strcpy -> memcpy
* since we have to know the string length anyway
-rw-r--r-- | src/editor.c | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/src/editor.c b/src/editor.c index e4046c1..1360241 100644 --- a/src/editor.c +++ b/src/editor.c @@ -103,19 +103,22 @@ rp_input_line * input_line_new (char *prompt, char *preinput, int history_id, completion_fn fn) { rp_input_line *line; + size_t length; line = xmalloc (sizeof (rp_input_line)); line->prompt = prompt; line->compl = completions_new (fn); line->history_id = history_id; - /* Allocate some memory to start with */ - line->size = strlen (preinput) + 100; + /* Allocate some memory to start with (100 extra bytes) */ + length = strlen (preinput); + line->size = length + 1 + 100; line->buffer = xmalloc (line->size); /* load in the preinput */ - strcpy (line->buffer, preinput); - line->position = line->length = strlen (preinput); + memcpy (line->buffer, preinput, length); + line->buffer[length] = '\0'; + line->position = line->length = length; return line; } |