Le nonidi 9 frimaire, an CCXXIV, Ganesh Ajjanagadde a écrit :
> >>      end = p + strlen(p) - 1;

> Don't know what you are referring to here, but dereferencing is
> clearly invalid. However, in order to allow common loop idioms,
> pointer arithmetic one element beyond a array (memory) range is valid:

Of course. But one element BEFORE the beginning of an array is invalid. In
other words p + sizeof(p) is valid (assuming p is char[]), but p - 1 is not.

In this instance, if p is a 0-terminated string, p + strlen(p) is always
valid, even without the provision you mention, because the 0 is part of the
object. But p + strlen(p) - 1 is not, if strlen(p) can be 0.

Note that dereferencing or not is not relevant: some architectures have
special registers for pointers that would cause traps just loading an
invalid pointer (think: p at offset 0 of segment S, p-1 at offset max of
segment S-1 -> load segment descriptor). FFmpeg probably does not run on any
such architecture, though. But still, this is bad style.

Regards,

-- 
  Nicolas George

Attachment: signature.asc
Description: Digital signature

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel

Reply via email to