martanne / vis

A vi-like editor based on Plan 9's structural regular expressions
Other
4.19k stars 259 forks source link

vis-menu.c: add space for terminating NUL byte #1135

Closed tosch42 closed 9 months ago

mcepl commented 9 months ago

Hmm, isn’t it cutting off the last character of text?

rnpnr commented 9 months ago

Thanks for the patch Tom! I will apply it now.

vis-menu inherited a lot of rough code from slmenu and it really needs a rework. This certainly fixes one issue.

Hmm, isn’t it cutting off the last character of text?

No, the sizeof operator in C has no knowledge of the contents of the buffer text. It simply returns the amount of static memory allocated for it. If sel->text is as long or longer than sizeof(text) then the string copied into text will not be terminated by NUL (aka \0, aka 0). text is memset() to \0 at the start of this loop.

Hope this helps!

tosch42 commented 9 months ago

Thanks Randy. I currently have some time which allows me to look deeper into vis-menu. If I come up with a rewrite or some ideas, I'll let you know.