poke-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] Use xstrndup instead of xzmalloc+strncpy in poke_getc


From: Tim Rühsen
Subject: Re: [PATCH] Use xstrndup instead of xzmalloc+strncpy in poke_getc
Date: Thu, 9 Apr 2020 17:15:14 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.6.0

Oh, I see an even more elegant, non-destructive way.
Ignore this please, will resend soon.

On 4/9/20 5:05 PM, Tim Rühsen wrote:
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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]