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:46:53 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.6.0

Pushed.

On 4/9/20 5:32 PM, Jose E. Marchesi wrote:

Hi Tim.

     2020-04-09  Tim Rühsen  <address@hidden>

             * src/pk-repl.c: Include xstrndup.h.
             (poke_getc): Use xstrndup instead of xzmalloc+strncpy.

OK for master.
Thanks!


     ---
      ChangeLog     | 5 +++++
      src/pk-repl.c | 9 ++++-----
      2 files changed, 9 insertions(+), 5 deletions(-)

     diff --git a/ChangeLog b/ChangeLog
     index d3d156d3..a5b99007 100644
     --- a/ChangeLog
     +++ b/ChangeLog
     @@ -1,3 +1,8 @@
     +2020-04-09  Tim Rühsen  <address@hidden>
     +
     +  * src/pk-repl.c: Include xstrndup.h.
     +  (poke_getc): Use xstrndup instead of xzmalloc+strncpy.
     +
      2020-04-09  Tim Rühsen  <address@hidden>

        * lib/pkl-ast.c (pkl_struct_type_traverse): Use
     diff --git a/src/pk-repl.c b/src/pk-repl.c
     index 394f67b5..90d5d66d 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,13 +199,12 @@ 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);

     +  free (line_to_point);
     +
        if (cmd == NULL)
          rl_completion_entry_function = poke_completion_function;

     @@ -218,7 +218,6 @@ poke_getc (FILE *stream)
                   rl_completion_entry_function = null_completion_function;
               }
           }
     -  free (line_to_point);

        int c =  rl_getc (stream);

     --
     2.26.0




reply via email to

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