This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: US-CERT Vulnerability Note VU#162289


Mark Mitchell wrote:

> ...
>
> And:
>
>> Addition or subtraction of a pointer into, or just beyond, an array object
>> and an integer type produces a result that does not point into, or just
>> beyond, the same array object (6.5.6).
>>
>> is undefined behavior.

So then unless the compiler can determine that all pointers passed to foo,
for example below, represent a pointer to some Nth element of some array
from which not more than N will be effectively subtracted, the optimization
(if it can be called that) can not be performed, as a sum of a pointer and
an arbitrary integer may be validly be less than said pointer, as follows:

foo(char* p){
    if (p+(char*)-1 < p)
        <something> }

char a[] {0,1,2,3};

foo(a+2);

I believe.



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]