Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: metafy() (was Re: $watch, log and Cyrillic usernames)
- X-seq: zsh-workers 52215
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: zsh-workers@xxxxxxx
- Subject: Re: metafy() (was Re: $watch, log and Cyrillic usernames)
- Date: Sun, 8 Oct 2023 19:01:41 -0700
- Archived-at: <https://zsh.org/workers/52215>
- In-reply-to: <53125-1696801645.349232@KWzA.NFGU.Vwsy>
- List-id: <zsh-workers.zsh.org>
- References: <CAHJ=x4aS18Rez8yw=KBNqyNrdxAavshA36muRE=M3QzctD90Rw@mail.gmail.com> <51326-1696644317.959346@Oqom.p2Z_.86FS> <53125-1696801645.349232@KWzA.NFGU.Vwsy>
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