From: Johannes Schindelin <Johannes.Schindelin@gmx.de>
To: Eric Sunshine <sunshine@sunshineco.com>
Cc: gitgitgadget@gmail.com, Git List <git@vger.kernel.org>,
Junio C Hamano <gitster@pobox.com>
Subject: Re: [PATCH 2/3] getpwuid(mingw): provide a better default for the user name
Date: Tue, 16 Oct 2018 14:38:09 +0200 (DST) [thread overview]
Message-ID: <nycvar.QRO.7.76.6.1810161436480.4546@tvgsbejvaqbjf.bet> (raw)
In-Reply-To: <CAPig+cRbOOrC5_jCnR2ohMZWoYXfNqvWtj3m_JTpudJhV1mQng@mail.gmail.com>
Hi Eric,
On Mon, 15 Oct 2018, Eric Sunshine wrote:
> On Mon, Oct 15, 2018 at 5:47 AM Johannes Schindelin via GitGitGadget
> <gitgitgadget@gmail.com> wrote:
> > We do have the excellent GetUserInfoEx() function to obtain more
> > detailed information of the current user (if the user is part of a
> > Windows domain); Let's use it.
> > [...]
> > Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
> > ---
> > diff --git a/compat/mingw.c b/compat/mingw.c
> > @@ -1798,6 +1799,33 @@ int mingw_getpagesize(void)
> > +static char *get_extended_user_info(enum EXTENDED_NAME_FORMAT type)
> > +{
> > + DECLARE_PROC_ADDR(secur32.dll, BOOL, GetUserNameExW,
> > + enum EXTENDED_NAME_FORMAT, LPCWSTR, PULONG);
> > + static wchar_t wbuffer[1024];
>
> Does this need to be static? It's not being returned to the caller.
It does not. Fixed.
> > + len = ARRAY_SIZE(wbuffer);
> > + if (GetUserNameExW(type, wbuffer, &len)) {
> > + char *converted = xmalloc((len *= 3));
Oh wow. I *just* realized this. It is an off-by-one: the `xmalloc()` call
needs to receive `len + 1` to accommodate for the trailing NUL. Will fix,
too.
Ciao,
Dscho
> > + if (xwcstoutf(converted, wbuffer, len) >= 0)
> > + return converted;
> > + free(converted);
> > + }
>
> If xwcstoutf() fails, 'converted' is freed; otherwise, the allocated
> 'converted' is stored in the caller's statically held 'passwd' struct.
> Okay.
>
> > + return NULL;
> > +}
>
next prev parent reply other threads:[~2018-10-16 12:38 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-10-15 9:47 [PATCH 0/3] Provide a useful default user ident on Windows Johannes Schindelin via GitGitGadget
2018-10-15 9:47 ` [PATCH 1/3] getpwuid(mingw): initialize the structure only once Johannes Schindelin via GitGitGadget
2018-10-15 14:25 ` Eric Sunshine
2018-10-15 9:47 ` [PATCH 2/3] getpwuid(mingw): provide a better default for the user name Johannes Schindelin via GitGitGadget
2018-10-15 14:34 ` Eric Sunshine
2018-10-16 12:38 ` Johannes Schindelin [this message]
2018-10-16 12:41 ` Eric Sunshine
2018-10-16 13:06 ` Johannes Schindelin
2018-10-15 9:47 ` [PATCH 3/3] mingw: use domain information for default email Johannes Schindelin via GitGitGadget
2018-10-15 14:41 ` Eric Sunshine
2018-10-16 12:34 ` Johannes Schindelin
2018-10-16 3:59 ` Junio C Hamano
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
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=nycvar.QRO.7.76.6.1810161436480.4546@tvgsbejvaqbjf.bet \
--to=johannes.schindelin@gmx.de \
--cc=git@vger.kernel.org \
--cc=gitgitgadget@gmail.com \
--cc=gitster@pobox.com \
--cc=sunshine@sunshineco.com \
/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://80x24.org/mirrors/git.git
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 read-only IMAP folder(s) and NNTP newsgroup(s).