Re: [hackers] [dmenu] tab-complete: figure out the size before copying || NRK

From: Hiltjo Posthuma <hiltjo_AT_codemadness.org>
Date: Fri, 2 Sep 2022 19:10:38 +0200

On Fri, Sep 02, 2022 at 02:58:15PM +0300, Santtu Lakkala wrote:
> On 2.9.2022 14.01, git_AT_suckless.org wrote:
> > commit 528d39b011afb7ef6fd794ba6b74155d4e69bc68
> dmenu.c b/dmenu.c
> > index 969f6d8..6b285df 100644
> > --- a/dmenu.c
> > +++ b/dmenu.c
> > _AT_@ -517,9 +517,9 @@ insert:
> > case XK_Tab:
> > if (!sel)
> > return;
> > - strncpy(text, sel->text, sizeof text - 1);
> > + cursor = strnlen(sel->text, sizeof text - 1);
> > + memcpy(text, sel->text, cursor);
> > text[sizeof text - 1] = '\0'
> This should now be
> text[cursor] = '\0';
>
> (Try, for example:
> printf "short\nlongerstring\n" | dmenu
>
> and type in: lon<TAB><Home>^Ks<TAB>
> and end up with shortgerstring)
>
> > - cursor = strlen(text);
> > match();
> > break;
> > }
>
> --
> Santtu
>

Thank you!

-- 
Kind regards,
Hiltjo
Received on Fri Sep 02 2022 - 19:10:38 CEST

This archive was generated by hypermail 2.3.0 : Fri Sep 02 2022 - 19:12:37 CEST