Re: RES: RES: vt newcons mouse paste issue FIXED

From: Tomoaki AOKI <junchoon_at_dec.sakura.ne.jp>
Date: Wed, 22 Jun 2022 16:48:47 UTC
Hi.

Not actually tested, but this can cause breakage on non-ascii cases.
Maybe also (or instead) iswspace() test would be needed.
Possibly additional mbrtowc() in the argument of iswspace().

Please see `man 3 multibyte` and `man 3 iswspace`.
(Possibly more to see.)

Characters in buf can be multibyte or wide char depending on locale,
as vt can show at least UTF-8 characters.

Sorry, not looked into enough how UTF-8 characters outside ascii are
handled internally on vt.


On Wed, 22 Jun 2022 15:01:36 +0000
Ivan Quitschal <tezeka@hotmail.com> wrote:

> Hi Hans
> 
> Actually i can , I should've cut off the '\r' 😊 ,  this is what was causing the term to go bend
> 
> This is the correct diff (option -C 9999 doesn’t worked with -u)
> I also included your code for the pts anyway
> 
> 
> 
> --- sys/dev/vt/vt_buf.c.orig    2022-06-22 11:48:39.705597000 -0300
> +++ sys/dev/vt/vt_buf.c 2022-06-22 11:51:05.502415000 -0300
> @@ -41,6 +41,7 @@
>  #include <sys/malloc.h>
>  #include <sys/mutex.h>
>  #include <sys/reboot.h>
> +#include <sys/ctype.h>
>  
>  #include <dev/vt/vt.h>
>  
> @@ -752,6 +753,7 @@
>  {
>         int i, r, c, cs, ce;
>         term_pos_t s, e;
> +       term_char_t *end;
>  
>         /* Swap according to window coordinates. */
>         if (POS_INDEX(vtbuf_htw(vb, vb->vb_mark_start.tp_row),
> @@ -772,10 +774,15 @@
>                 for (c = cs; c < ce; c++) {
>                         buf[i++] = vb->vb_rows[r][c];
>                 }
> +               for (end = buf + i; end-- != buf; ) {
> +               if (isspace((unsigned char)*end) == false)
> +                       break;
> +               *end = '\0';
> +               }
>                 /* Add new line for all rows, but not for last one. */
>                 if (r != e.tp_row) {
> -                       buf[i++] = '\r';
>                         buf[i++] = '\n';
> +                       buf[i++] = '\0';
>                 }
>         }
>  }
> 
> Works fine here
> 
> Thanks
> 
> --tzk
> 
> -----Mensagem original-----
> De: Hans Petter Selasky <hps@selasky.org> 
> Enviada em: quarta-feira, 22 de junho de 2022 11:02
> Para: Ivan Quitschal <tezeka@hotmail.com>; freebsd-current@freebsd.org
> Assunto: Re: RES: vt newcons mouse paste issue FIXED
> 
> On 6/22/22 15:36, Ivan Quitschal wrote:
> > Hi Hans
> > 
> 
> Hi Ivan,
> 
> I think you should upload the diff at:
> 
> https://nam12.safelinks.protection.outlook.com/?url=https%3A%2F%2Freviews.freebsd.org%2Fdifferential%2F&amp;data=05%7C01%7C%7C85e3f391dfc941f2852908da5457c75f%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637915033252675801%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&amp;sdata=4sxXIR9NhIbwD42gIrP4pYcdnUinqae1SNZAjclr2Aw%3D&amp;reserved=0
> 
> Make the diff like this:
> 
> diff -u -C 999999 sys/dev/vt/vt_buf.c.orig sys/dev/vt/vt_buf.c > a.diff
> 
> 
> I see two issues:
> 
> 1) Pointer arithmetics is not so good!
> 
> >                 }
> > +               end = buf + i - 1;
> > +               while (end > buf && isspace((unsigned char)*end))
> > +               {
> > +                       *end = '\0';
> > +                       end--;
> > +               }
> > +
> 
> I think this would be better and avoid the ">" with pointers!
> 
> for (end = buf + i; end-- != buf; ) {
>     if (isspace((unsigned char)*end) == false)
> 	break;
>     *end = '\0';
> }
> 
> Can you explain this:
> 
> > -                       buf[i++] = '\r';
> > +                       buf[i] = '\r';
> >                         buf[i++] = '\n';
> 
> '\r' character is now overwritten by '\n' character.
> 
> --HPS
> 


-- 
Tomoaki AOKI    <junchoon@dec.sakura.ne.jp>