1
0
mirror of https://github.com/git/git synced 2024-06-30 22:54:27 +00:00

compat/win32: fix const-correctness with string constants

Adjust various places in our Win32 compatibility layer where we are not
assigning string constants to `const char *` variables.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Patrick Steinhardt 2024-06-07 08:38:44 +02:00 committed by Junio C Hamano
parent 9c076c32fb
commit e7b40195ae
3 changed files with 31 additions and 15 deletions

View File

@ -10,7 +10,13 @@ char *gitbasename (char *path)
skip_dos_drive_prefix(&path); skip_dos_drive_prefix(&path);
if (!path || !*path) if (!path || !*path)
return "."; /*
* basename(3P) is mis-specified because it returns a
* non-constant pointer even though it is specified to return a
* pointer to internal memory at times. The cast is a result of
* that.
*/
return (char *) ".";
for (base = path; *path; path++) { for (base = path; *path; path++) {
if (!is_dir_sep(*path)) if (!is_dir_sep(*path))
@ -34,7 +40,13 @@ char *gitdirname(char *path)
int dos_drive_prefix; int dos_drive_prefix;
if (!p) if (!p)
return "."; /*
* dirname(3P) is mis-specified because it returns a
* non-constant pointer even though it is specified to return a
* pointer to internal memory at times. The cast is a result of
* that.
*/
return (char *) ".";
if ((dos_drive_prefix = skip_dos_drive_prefix(&p)) && !*p) if ((dos_drive_prefix = skip_dos_drive_prefix(&p)) && !*p)
goto dot; goto dot;

View File

@ -2279,7 +2279,11 @@ struct passwd *getpwuid(int uid)
p->pw_name = user_name; p->pw_name = user_name;
p->pw_gecos = get_extended_user_info(NameDisplay); p->pw_gecos = get_extended_user_info(NameDisplay);
if (!p->pw_gecos) if (!p->pw_gecos)
p->pw_gecos = "unknown"; /*
* Data returned by getpwuid(3P) is treated as internal and
* must never be written to or freed.
*/
p->pw_gecos = (char *) "unknown";
p->pw_dir = NULL; p->pw_dir = NULL;
initialized = 1; initialized = 1;
@ -2800,16 +2804,16 @@ int is_path_owned_by_current_sid(const char *path, struct strbuf *report)
strbuf_addf(report, "'%s' is on a file system that does " strbuf_addf(report, "'%s' is on a file system that does "
"not record ownership\n", path); "not record ownership\n", path);
} else if (report) { } else if (report) {
LPSTR str1, str2, str3, str4, to_free1 = NULL, PCSTR str1, str2, str3, str4;
to_free3 = NULL, to_local_free2 = NULL, LPSTR to_free1 = NULL, to_free3 = NULL,
to_local_free4 = NULL; to_local_free2 = NULL, to_local_free4 = NULL;
if (user_sid_to_user_name(sid, &str1)) if (user_sid_to_user_name(sid, &to_free1))
to_free1 = str1; str1 = to_free1;
else else
str1 = "(inconvertible)"; str1 = "(inconvertible)";
if (ConvertSidToStringSidA(sid, &str2)) if (ConvertSidToStringSidA(sid, &to_local_free2))
to_local_free2 = str2; str2 = to_local_free2;
else else
str2 = "(inconvertible)"; str2 = "(inconvertible)";
@ -2822,13 +2826,13 @@ int is_path_owned_by_current_sid(const char *path, struct strbuf *report)
str4 = "(invalid)"; str4 = "(invalid)";
} else { } else {
if (user_sid_to_user_name(current_user_sid, if (user_sid_to_user_name(current_user_sid,
&str3)) &to_free3))
to_free3 = str3; str3 = to_free3;
else else
str3 = "(inconvertible)"; str3 = "(inconvertible)";
if (ConvertSidToStringSidA(current_user_sid, if (ConvertSidToStringSidA(current_user_sid,
&str4)) &to_local_free4))
to_local_free4 = str4; str4 = to_local_free4;
else else
str4 = "(inconvertible)"; str4 = "(inconvertible)";
} }

View File

@ -139,7 +139,7 @@ static void write_console(unsigned char *str, size_t len)
/* convert utf-8 to utf-16 */ /* convert utf-8 to utf-16 */
int wlen = xutftowcsn(wbuf, (char*) str, ARRAY_SIZE(wbuf), len); int wlen = xutftowcsn(wbuf, (char*) str, ARRAY_SIZE(wbuf), len);
if (wlen < 0) { if (wlen < 0) {
wchar_t *err = L"[invalid]"; const wchar_t *err = L"[invalid]";
WriteConsoleW(console, err, wcslen(err), &dummy, NULL); WriteConsoleW(console, err, wcslen(err), &dummy, NULL);
return; return;
} }