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: Jose E. Marchesi
Subject: Re: [PATCH] Use xstrndup instead of xzmalloc+strncpy in poke_getc
Date: Thu, 09 Apr 2020 17:32:56 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

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]