[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Invalid use of const pointer?
From: |
Henrik Carlqvist |
Subject: |
Re: Invalid use of const pointer? |
Date: |
Sat, 8 Jan 2022 22:34:26 +0100 |
On Sat, 08 Jan 2022 15:36:46 -0500
Paul Smith <psmith@gnu.org> wrote:
> On Sat, 2022-01-08 at 19:47 +0100, Henrik Carlqvist wrote:
> > 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.
I mean this code, where name is a const char * which was an input variable to
the function:
# if !defined(_AMIGA) && !defined(WINDOWS32)
else
{
struct passwd *pwent;
char *userend = strchr (name + 1, '/');
if (userend != 0)
*userend = '\0'; <--- ** Here userend modifies the content
pwent = getpwnam (name + 1);
if (pwent != 0)
{
if (userend == 0)
return xstrdup (pwent->pw_dir);
else
return xstrdup (concat (3, pwent->pw_dir, "/", userend + 1)); <--X
}
else if (userend != 0)
*userend = '/'; <--- ** Here userend restores the content
}
# endif /* !AMIGA && !WINDOWS32 */
> 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.
But what about the case marked with <--X above? To me it seems as if the
function returns after having modified const char *name bu using userend.
Best regards Henrik
- Invalid use of const pointer?, Joe Filion, 2022/01/07
- Re: Invalid use of const pointer?, Paul Smith, 2022/01/08
- Re: Invalid use of const pointer?, Henrik Carlqvist, 2022/01/08
- Re: Invalid use of const pointer?, Paul Smith, 2022/01/08
- Re: Invalid use of const pointer?,
Henrik Carlqvist <=
- Re: Invalid use of const pointer?, Paul Smith, 2022/01/08
- Re: Invalid use of const pointer?, Henrik Carlqvist, 2022/01/09
- Re: Invalid use of const pointer?, Paul Smith, 2022/01/09
- Re: Invalid use of const pointer?, Henrik Carlqvist, 2022/01/09
- Re: Invalid use of const pointer?, Edward Welbourne, 2022/01/11
- Re: Invalid use of const pointer?, Paul Smith, 2022/01/11
- RE: Invalid use of const pointer?, Joe Filion, 2022/01/09
- Re: Invalid use of const pointer?, Paul Smith, 2022/01/17
- Re: Invalid use of const pointer?, Jon Forrest, 2022/01/17
- RE: Invalid use of const pointer?, Joe Filion, 2022/01/18