[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: Tue, 11 Jan 2022 08:29:36 -0500
User-agent: Evolution 3.36.5-0ubuntu1

On Tue, 2022-01-11 at 10:57 +0000, Edward Welbourne wrote:
> Indeed.  The compiler is allowed to place a string literal in read-
> only memory, where modifying it (even if you do "put it back the way
> it was" later) is an access violation.  Passing such a const char *
> to your function would thus crash.

Of course, I'm very well aware of all of this.

But, in fact, it's not possible for make to pass a string literal to
this function.  So your scenario will never happen.

As I've said in other messages in this thread, the right way to fix
this, if we wanted to fix it, would be to allocate separate memory and
copy the substring into that so that the original string would not be
modified.  It's the WRONG behavior to start de-constifying swaths of
the program to allow a low-level method to modify strings.

reply via email to

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