Skip to content

Commit 4478ad3

Browse files
dschogitster
authored andcommitted
ident: stop assuming that gw_gecos is writable
In 590e081 (ident: add NO_GECOS_IN_PWENT for systems without pw_gecos in struct passwd, 2011-05-19), code was introduced to iterate over the `gw_gecos` field; The loop variable is of type `char *`, which assumes that `gw_gecos` is writable. However, it is not necessarily writable (and it is a bad idea to have it writable in the first place), so let's switch the loop variable type to `const char *`. This is not a new problem, but what is new is the Meson build. While it does not trigger in CI builds, imitating the commands of `ci/run-build-and-tests.sh` in a regular Git for Windows SDK (`meson setup build . --fatal-meson-warnings --warnlevel 2 --werror --wrap-mode nofallback -Dfuzzers=true` followed by `meson compile -C build --` results in this beautiful error: "cc" [...] -o libgit.a.p/ident.c.obj "-c" ../ident.c ../ident.c: In function 'copy_gecos': ../ident.c:68:18: error: assignment discards 'const' qualifier from pointer target type [-Werror=discarded-qualifiers] 68 | for (src = get_gecos(w); *src && *src != ','; src++) { | ^ cc1.exe: all warnings being treated as errors Now, why does this not trigger in CI? The answer is as simple as it is puzzling: The `win+Meson` job completely side-steps Git for Windows' development environment, opting instead to use the GCC that is on the `PATH` in GitHub-hosted `windows-latest` runners. That GCC is pinned to v12.2.0 and targets the UCRT (unlikely to change any time soon, see https://github.com/actions/runner-images/blob/win25/20250303.1/images/windows/toolsets/toolset-2022.json#L132-L141). That is in stark contrast to Git for Windows, which uses GCC v14.2.0 and targets MSVCRT. Git for Windows' `Makefile`-based build also obviously uses different compiler flags, otherwise this compile error would have had plenty of opportunity in almost 14 years to surface. In other words, contrary to my expectations, the `win+Meson` job is ill-equipped to replace the `win build` job because it exercises a completely different tool version/compiler flags vector than what Git for Windows needs. Nevertheless, there is currently this huge push, including breaking changes after -rc1 and all, for switching to Meson. Therefore, we need to make it work, somehow, even in Git for Windows' SDK, hence this patch, at this point in time. Signed-off-by: Johannes Schindelin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e969bc8 commit 4478ad3

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

ident.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ static struct passwd *xgetpwuid_self(int *is_bogus)
5959

6060
static void copy_gecos(const struct passwd *w, struct strbuf *name)
6161
{
62-
char *src;
62+
const char *src;
6363

6464
/* Traditionally GECOS field had office phone numbers etc, separated
6565
* with commas. Also & stands for capitalized form of the login name.

0 commit comments

Comments
 (0)