Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: metafy() (was Re: $watch, log and Cyrillic usernames)



On Sun, Oct 8, 2023 at 2:47 PM Oliver Kiddle <opk@xxxxxxx> wrote:
>
> I'm not sure what the best approach is for the watch module. Subtracting 1
> from n in each call to strnlen() avoids writing a null past the end of
> the buffer but is not ideal for 32 character usernames. Using
> META_HEAPDUP instead means a lot of heap allocations in the normal case
> where there are only short ASCII-only usernames. Any ideas?

Handle the special case explicitly?  If I follow your explanation,
something like this?

        int len = strnlen(u->ut_name, sizeof(u->ut_name));
        char *username = metafy(u->ut_name, len,
                                (len == sizeof(u->ut_name) ?
                                 META_HEAPDUP /* allow for nul terminator */ :
                                 META_USEHEAP));




Messages sorted by: Reverse Date, Date, Thread, Author