[Top][All Lists]

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

[Bug-readline] A bug in complete.c if HANDLE_MULTIBYTE is undefined.

From: Juan Manuel Guerrero
Subject: [Bug-readline] A bug in complete.c if HANDLE_MULTIBYTE is undefined.
Date: Tue, 04 Jul 2017 21:26:49 +0200
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; de; rv: Gecko/20101206 SUSE/3.1.7 Thunderbird/3.1.7

I have tried to build readline-7.0 for MSDOS/FreeDOS using DJGPP.  The only
important issue here is that the used system does not provide multi-byte
support at all thus NO_MULTIBYTE_SUPPORT is defined to 1 and HANDLE_MULTIBYTE
is undefined.  This triggers at least one bug.

In function fnprint of file complete.c the variable print_len is initialized
with the return value of strlen, but that happens only iff HANDLE_MULTIBYTE
is defined.  Else this variable is never initialized but later used in line 828:

  if (_rl_completion_prefix_display_length > 0 && prefix_bytes >= print_len)  
<-- used without initialization!
    prefix_bytes = 0;

Either this "if" clause must also be guarded by #if defined (HANDLE_MULTIBYTE)
or the variable must be initialized as shown in the patch.  There are also
some superfluous variables and some other variables that are only used if
HANDLE_MULTIBYTE is defined.  They are used inside of "if" clauses of loops
and could be defined there instead at the beginning of the function so that
the compiler does not warn if compiling with the pedantic and -Wall flag.
But that is of course only a design question.  It is purely a matter of taste.
I send you a small patch made against main branch of the readline repository
in the hope that it may be helpfull.

Juan M. Guerrero

        * bind.c (rl_parse_and_bind): unused variable `s' fixed.

        * complete.c (fnprint): 'print_len' might be used uninitialized in this
        function fixed.
        (rl_menu_complete): unused variable `cstate' fixed.

        * display.c (expand_prompt): unused variable `ind' and `pind' fixed.
        (rl_redisplay): unused variable `p' and `z' fixed.
        (_rl_move_cursor_relative): unused variable `adjust' and `in_invisline' 

        * readline.c (readline_internal_char): unused variable `eof_found'

        * vi_mode.c (rl_vi_domove): unused variable `r' fixed.

diff --git a/bind.c b/bind.c
index f1098c4..73537fb 100644
--- a/bind.c
+++ b/bind.c
@@ -1344,7 +1344,6 @@ rl_parse_and_bind (string)
   if (_rl_stricmp (string, "set") == 0)
       char *var, *value, *e;
-      int s;

       var = string + i;
       /* Make VAR point to start of variable name. */
diff --git a/complete.c b/complete.c
index 0a81129..220b4de 100644
--- a/complete.c
+++ b/complete.c
@@ -807,7 +807,7 @@ fnprint (to_print, prefix_bytes, real_pathname)
   int printed_len, w;
   const char *s;
-  int common_prefix_len, print_len;
+  int common_prefix_len, print_len = strlen (to_print);
 #if defined (HANDLE_MULTIBYTE)
   mbstate_t ps;
   const char *end;
@@ -815,7 +815,6 @@ fnprint (to_print, prefix_bytes, real_pathname)
   int width;
   wchar_t wc;

-  print_len = strlen (to_print);
   end = to_print + print_len + 1;
   memset (&ps, 0, sizeof (mbstate_t));
@@ -2839,7 +2838,7 @@ rl_menu_complete (count, ignore)
   static int full_completion = 0;      /* set to 1 if menu completion should 
reinitialize on next call */
   static int orig_start, orig_end;
   static char quote_char;
-  static int delimiter, cstate;
+  static int delimiter;

   /* The first time through, we generate the list of matches and set things
      up to insert them. */
diff --git a/display.c b/display.c
index 41fb053..d3e6353 100644
--- a/display.c
+++ b/display.c
@@ -311,8 +311,11 @@ expand_prompt (pmt, flags, lp, lip, niflp, vlp)
      int *lp, *lip, *niflp, *vlp;
   char *r, *ret, *p, *igstart, *nprompt, *ms;
-  int l, rl, last, ignoring, ninvis, invfl, invflset, ind, pind, physchars;
+  int l, rl, last, ignoring, ninvis, invfl, invflset, physchars;
   int mlen;
+#if defined (HANDLE_MULTIBYTE)
+  int ind, pind;

   /* We only expand the mode string for the last line of a multiline prompt
      (a prompt with embedded newlines). */
@@ -582,10 +585,11 @@ rl_redisplay ()
   register int in, out, c, linenum, cursor_linenum;
   register char *line;
   int inv_botlin, lb_botlin, lb_linenum, o_cpos;
-  int newlines, lpos, temp, n0, num, prompt_lines_estimate;
+  int newlines, lpos, temp, prompt_lines_estimate;
   char *prompt_this_line;
   int mb_cur_max = MB_CUR_MAX;
 #if defined (HANDLE_MULTIBYTE)
+  int  n0, num;
   wchar_t wc;
   size_t wc_bytes;
   int wc_width;
@@ -762,7 +766,6 @@ rl_redisplay ()
      contents of the command line? */
   while (lpos >= _rl_screenwidth)
-      int z, p;
       int nocorrect, wadjust;

       nocorrect = 0;
@@ -790,7 +793,7 @@ rl_redisplay ()
              /* This has to take invisible characters in the prompt into
                 account. */
-             z = _rl_col_width  (local_prompt, n0, num, 1) - wadjust;
+             int z = _rl_col_width  (local_prompt, n0, num, 1) - wadjust;
              if (z > _rl_screenwidth)
                  num = _rl_find_prev_mbchar (local_prompt, num, MB_FIND_ANY);
@@ -802,7 +805,7 @@ rl_redisplay ()
                     character, we want to move to the start, then find out
                     where it ends so we know where to insert the newline.
                     If this isn't a multibyte character, its the same as num++ 
-                 p = _rl_find_prev_mbchar (local_prompt, num, MB_FIND_ANY);
+                 int p = _rl_find_prev_mbchar (local_prompt, num, MB_FIND_ANY);
                  num = _rl_find_next_mbchar (local_prompt, p, 1, MB_FIND_ANY);
@@ -2162,8 +2165,6 @@ _rl_move_cursor_relative (new, data)
   register int i;
   int woff;                    /* number of invisible chars on current line */
   int cpos, dpos;              /* current and desired cursor positions */
-  int adjust;
-  int in_invisline;
   int mb_cur_max = MB_CUR_MAX;

   woff = WRAP_OFFSET (_rl_last_v_pos, wrap_offset);
@@ -2180,6 +2181,8 @@ _rl_move_cursor_relative (new, data)
      as long as we are past them and they are counted by _rl_col_width. */
   if (mb_cur_max > 1 && rl_byte_oriented == 0)
+      int adjust, in_invisline;
       adjust = 1;
       /* Try to short-circuit common cases and eliminate a bunch of multibyte
         character function calls. */
diff --git a/readline.c b/readline.c
index e51df4f..e0688de 100644
--- a/readline.c
+++ b/readline.c
@@ -529,7 +529,10 @@ readline_internal_char ()
 readline_internal_charloop ()
-  static int lastc, eof_found;
+#if !defined (READLINE_CALLBACKS)
+  static int eof_found;
+  static int lastc;
   int c, code, lk;

   lastc = EOF;
diff --git a/vi_mode.c b/vi_mode.c
index 56d2e72..0bd757c 100644
--- a/vi_mode.c
+++ b/vi_mode.c
@@ -1293,7 +1293,6 @@ int
 rl_vi_domove (x, ignore)
      int x, *ignore;
-  int r;
   _rl_vimotion_cxt *m;

   m = _rl_vimvcxt;

reply via email to

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