[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Invalid use of const pointer?

From: Paul Smith
Subject: Re: Invalid use of const pointer?
Date: Sat, 08 Jan 2022 15:36:46 -0500
User-agent: Evolution 3.36.5-0ubuntu1

On Sat, 2022-01-08 at 19:47 +0100, Henrik Carlqvist wrote:
> On Sat, 08 Jan 2022 10:37:17 -0500
> Paul Smith <psmith@gnu.org> wrote:
> > The const-correct way to write this code would be to allocate a new
> > string and modify that
> Another correct way to do this would be to not declare the input
> variable *name as const, but that would need to spread up to calling
> functions.

Indeed.  We explicitly don't want to do that.

> There are cases in tilde_expand when *userend is restored restored to
> '/' after having being altered to '\0'. In those cases at least no
> permanent changes has been made to the const string seen from the
> calling functions point of view.


>  But now, with both userend and pwent set it seems as if the calling
> function will have its const string modified. If this final case were
> fixed at least no calling function would suffer from a modified const
> string.

I'm not sure what you mean here.  It is never the case that the
incoming string (name) is ever modified under any circumstances, as far
as the calling function is concerned.

If the incoming string needs to expanded then a new string is allocated
and returned from this function containing the expansion.  If the
incoming string is not expanded, then no new string is allocated and 0
(null pointer) is returned.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]