[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] Use xstrndup instead of xzmalloc+strncpy in poke_getc
From: |
Tim Rühsen |
Subject: |
[PATCH] Use xstrndup instead of xzmalloc+strncpy in poke_getc |
Date: |
Thu, 9 Apr 2020 17:05:57 +0200 |
2020-04-09 Tim Rühsen <address@hidden>
* src/pk-repl.c: Include xstrndup.h.
(poke_getc): Use xstrndup instead of xzmalloc+strncpy.
---
ChangeLog | 5 +++++
src/pk-repl.c | 6 ++----
2 files changed, 7 insertions(+), 4 deletions(-)
diff --git a/src/pk-repl.c b/src/pk-repl.c
index 394f67b5..46d78cc1 100644
--- a/src/pk-repl.c
+++ b/src/pk-repl.c
@@ -29,6 +29,7 @@
#include <gettext.h>
#define _(str) dgettext (PACKAGE, str)
#include "xalloc.h"
+#include "xstrndup.h"
#include "poke.h"
#include "pk-term.h"
@@ -198,10 +199,7 @@ space_substitute_redisplay (void)
static int
poke_getc (FILE *stream)
{
- char *line_to_point = xzalloc (rl_point + 1);
- int end = rl_point ? rl_point - 1 : 0;
- strncpy (line_to_point, rl_line_buffer, end);
-
+ char *line_to_point = xstrndup (rl_line_buffer, rl_point ? rl_point - 1 : 0);
char *tok = strtok (line_to_point, "\t ");
const struct pk_cmd *cmd = pk_cmd_find (tok);
--
2.26.0
- [PATCH] Use xstrndup instead of xzmalloc+strncpy in poke_getc,
Tim Rühsen <=