RE: Invalid use of const pointer?

2022-01-09 Thread Joe Filion
 Regarding: “This Thanks mostly goes to Joe Filion who initally noticed this.” Your welcome. If interested, I found another similar construct in another area of the code. Don’t worry, this appears to be the last one. On line 557 of implicit.c:   p = strchr (nptr, '%'); nptr is a const pointer, but p is used as a non-const pointer later on and modifies the string. Joe Sent from Mail for Windows From: Henrik CarlqvistSent: Sunday, January 9, 2022 5:06 AMTo: psm...@gnu.orgCc: joefili...@gmail.com; bug-make@gnu.orgSubject: Re: Invalid use of const pointer? On Sat, 08 Jan 2022 17:29:33 -0500Paul Smith  wrote:> It turns out to be innocuous because none of the callers care that the> value of the input string is modified if we return a different string,> but it's still wrong and should be fixed. If so, the easy and more correct fix might be to to remove const from thefunction variable declarations rather than to restore the value. > Thanks for noticing! This Thanks mostly goes to Joe Filion who initally noticed this. Best regards Henrik 



Re: Invalid use of const pointer?

2022-01-09 Thread Henrik Carlqvist
On Sun, 09 Jan 2022 10:17:10 -0500
Paul Smith  wrote:
> In any event, the bug still exists whether you say the argument is
> const or not: the expectation when this function is called is that
> after it returns the string passed to it has the same content as before
> it was called.

If so I agree that the best quick and easy fix would be to restore the
original value. A fix involving more work would be to copy the const
input string to some temporary string that the function is free to alter as it
wants.

Best regards Henrik



Re: Invalid use of const pointer?

2022-01-09 Thread Paul Smith
On Sun, 2022-01-09 at 11:06 +0100, Henrik Carlqvist wrote:
> On Sat, 08 Jan 2022 17:29:33 -0500 Paul Smith  wrote:
> > It turns out to be innocuous because none of the callers care that
> > the value of the input string is modified if we return a different
> > string, but it's still wrong and should be fixed.
> 
> If so, the easy and more correct fix might be to to remove const from
> the function variable declarations rather than to restore the value.

It's not that easy.  Removing the const from the argument means that we
have to change all the caller's types to remove const, and that means
all the callers of those methods have to remove const, etc.

In any event, the bug still exists whether you say the argument is
const or not: the expectation when this function is called is that
after it returns the string passed to it has the same content as before
it was called.




Re: Invalid use of const pointer?

2022-01-09 Thread Henrik Carlqvist
On Sat, 08 Jan 2022 17:29:33 -0500
Paul Smith  wrote:
> It turns out to be innocuous because none of the callers care that the
> value of the input string is modified if we return a different string,
> but it's still wrong and should be fixed.

If so, the easy and more correct fix might be to to remove const from the
function variable declarations rather than to restore the value.

> Thanks for noticing!

This Thanks mostly goes to Joe Filion who initally noticed this.

Best regards Henrik