xquartz dereferencing a NULL pointer (patch 2)
glynn at gclements.plus.com
Fri Nov 7 03:05:38 PST 2008
Simon Thum wrote:
> > newtail = (oldtail + 1) % QUEUE_SIZE;
> > miEventQueue.tail = newtail;
> > becoming
> > miEventQueue.tail++;
> > miEventQueue.tail |= QUEUE_SIZE - 1;
Er, shouldn't this be "&=" ?
> I don't think a compiler should be doing this to a non-local store. It
> could probably be considered a bug. C doesn't really have a memory model
> but few rules likely to forbid this. I didn't check, but I'd be highly
> surprised by this being legal.
Unless an lvalue is declared "volatile", the compiler is free to
generate code which modifies it as and when it sees fit, so long as it
has the correct value "in the end". In the meantime, it can freely
store arbitrary data there if it wishes.
This is why the "volatile" keyword was added to the ANSI C standard:
so that the compiler could optimise memory access as it saw fit, while
providing an opt-out for the cases where "intermediate" values are
significant (signals, interrupts, memory-mapped I/O, threads, etc).
Glynn Clements <glynn at gclements.plus.com>
More information about the xorg