zsh-workers
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: zsh-workers@zsh.org
Subject: Re: metafy() (was Re: $watch, log and Cyrillic usernames)
Date: Sun, 8 Oct 2023 19:01:41 -0700	[thread overview]
Message-ID: <CAH+w=7au-TztJj9KbrNTEhLPWadaaWnm6qWGkJ3kgnX-QXZgXw@mail.gmail.com> (raw)
In-Reply-To: <53125-1696801645.349232@KWzA.NFGU.Vwsy>

On Sun, Oct 8, 2023 at 2:47 PM Oliver Kiddle <opk@zsh.org> 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));


  reply	other threads:[~2023-10-09  2:02 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-05 21:29 $watch, log and Cyrillic usernames Максим
2023-10-05 21:42 ` Bart Schaefer
2023-10-07  2:05 ` Oliver Kiddle
2023-10-07 16:49   ` Максим
2023-10-08  0:24     ` Oliver Kiddle
2023-10-08  6:20       ` Максим
2023-10-08 21:47   ` metafy() (was Re: $watch, log and Cyrillic usernames) Oliver Kiddle
2023-10-09  2:01     ` Bart Schaefer [this message]
2023-10-10 21:46       ` Oliver Kiddle

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAH+w=7au-TztJj9KbrNTEhLPWadaaWnm6qWGkJ3kgnX-QXZgXw@mail.gmail.com' \
    --to=schaefer@brasslantern.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).