bug-make
[Top][All Lists]
Advanced

[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 19:47:40 +0100

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 (or, rework the entire program to use the
> equivalent of C++'s std::string_view), but the author of this code
> (might be me, might be someone else: I didn't investigate) decided that
> the quick and dirty way had enough benefits to outweigh the gross-ness.

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.

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.

Best regards Henrik



reply via email to

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