]> git.ipfire.org Git - thirdparty/git.git/commitdiff
ident: add casts for fallback name and GECOS
authorPatrick Steinhardt <ps@pks.im>
Fri, 7 Jun 2024 06:38:25 +0000 (08:38 +0200)
committerJunio C Hamano <gitster@pobox.com>
Fri, 7 Jun 2024 17:30:51 +0000 (10:30 -0700)
In `xgetpwuid_self()`, we return a fallback identity when it was not
possible to look up the current identity. This fallback identity needs
to be internal and must never be written to by the calles as specified
by getpwuid(3P). As both the `pw_name` and `pw_gecos` fields are marked
as non-constant though, it will cause a warning to assign constant
strings to them once compiling with `-Wwrite-strings`.

Add explicit casts to avoid the warning.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
ident.c

diff --git a/ident.c b/ident.c
index cc7afdbf8197e981e02b6257a4618197063db69f..caf41fb2a98f56400764d87244635fd21750c13c 100644 (file)
--- a/ident.c
+++ b/ident.c
@@ -46,9 +46,9 @@ static struct passwd *xgetpwuid_self(int *is_bogus)
        pw = getpwuid(getuid());
        if (!pw) {
                static struct passwd fallback;
-               fallback.pw_name = "unknown";
+               fallback.pw_name = (char *) "unknown";
 #ifndef NO_GECOS_IN_PWENT
-               fallback.pw_gecos = "Unknown";
+               fallback.pw_gecos = (char *) "Unknown";
 #endif
                pw = &fallback;
                if (is_bogus)