[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [bug #60798] Make does not compile with GCC 11.1.0
From: |
Paul Smith |
Subject: |
Re: [bug #60798] Make does not compile with GCC 11.1.0 |
Date: |
Sat, 19 Jun 2021 12:32:55 -0400 |
User-agent: |
Evolution 3.36.5-0ubuntu1 |
On Sat, 2021-06-19 at 16:23 +0100, Dmitrii Pasechnik wrote:
> > I don't think I understand.
>
> p[] occupies a continuous memory area, starting from p[0], but p[-1]
> is not guaranteed by the standard to be accessible for you (well,
> unless you control the memory layout by placing p in a struct, not as
> the 1st member, but then why would you need p[-1] in the 1st place?)
>
> What's unclear about it?
The problem is that your initial premise is not correct. p here is not
an array, it's a pointer. If we had declared it like this:
char p[10]
then p[-1] would be problematic. But, we don't declare that.
We declare it like this:
char *p
so p is a pointer. It points to some memory, and it can (and does)
move both forward AND backward through that memory, via p+X and p-X.
That's perfectly legitimate and not illegal or a hack in any way.
I guess the compiler believes that it's possible that p might point to
the very start of some legitimate memory, and if that were true then
p[-1] (or, equivalently, *(p-1)) would be undefined behavior.
But, as human programmers we can examine this code and understand that
actually, it's never possible for p to point to the first character of
the array: we know that eval_strings->idx is never 0, so we know that p
will always be incremented past the beginning of the memory buffer:
p = value = alloca (len);
for (i = 0; i < eval_strings->idx; ++i)
{
...
*(p++) = ' ';
}
p[-1] = '\0';
- [bug #60798] Make does not compile with GCC 11.1.0, anonyme, 2021/06/18
- [bug #60798] Make does not compile with GCC 11.1.0, Paul D. Smith, 2021/06/18
- Re: [bug #60798] Make does not compile with GCC 11.1.0, Dmitrii Pasechnik, 2021/06/19
- Re: [bug #60798] Make does not compile with GCC 11.1.0, Paul Smith, 2021/06/19
- Re: [bug #60798] Make does not compile with GCC 11.1.0, Eli Zaretskii, 2021/06/19
- Re: [bug #60798] Make does not compile with GCC 11.1.0, Dmitrii Pasechnik, 2021/06/19
- Re: [bug #60798] Make does not compile with GCC 11.1.0,
Paul Smith <=
- Re: [bug #60798] Make does not compile with GCC 11.1.0, Andreas Schwab, 2021/06/21
- Re: [bug #60798] Make does not compile with GCC 11.1.0, David A. Wheeler, 2021/06/21
- Re: [bug #60798] Make does not compile with GCC 11.1.0, RANDRIANAINA Georges Aaron, 2021/06/21
- Re: [bug #60798] Make does not compile with GCC 11.1.0, Dmitry Goncharov, 2021/06/19
- Re: [bug #60798] Make does not compile with GCC 11.1.0, Dmitrii Pasechnik, 2021/06/19
- Re: [bug #60798] Make does not compile with GCC 11.1.0, Eli Zaretskii, 2021/06/19