Re: [PATCH v3 15/27] compat/win32: fix const-correctness with string constants
- From
Eric Sunshine <sunshine@sunshineco.com>
- Date
- Jun 3, 2024, 16:57 UTC
- Message-ID
- <CAPig+cTC83ZE2kGy=epeRFJ7a3jjRQXsvUYzB6jdOYfmy0yVOg@mail.gmail.com>
- In-Reply-To
- <3d92528125ee419aefdac790dc1a4106be632c60.1717402403.git.ps@pks.im>
On Mon, Jun 3, 2024 at 5:46 AM Patrick Steinhardt <ps@pks.im> wrote:
Show 18 quoted lines
> 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> > --- > diff --git a/compat/basename.c b/compat/basename.c > @@ -1,6 +1,8 @@ > +static char current_directory[] = "."; > @@ -10,7 +12,13 @@ char *gitbasename (char *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 *) "";
The change from returning "." to returning "" is unexplained by the commit message. Did you mean to return the newly-introduced `current_directory` instead?
Show 10 quoted lines
> @@ -34,7 +42,13 @@ char *gitdirname(char *path) > 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 *) "";
Ditto.