[ros-dev] gcc problem or not

Hartmut Birr hartmut.birr at gmx.de
Wed May 4 00:24:21 CEST 2005


Danny Smith wrote:

>  
>
>>-----Original Message-----
>>From: ros-dev-bounces at reactos.com 
>>[mailto:ros-dev-bounces at reactos.com] On Behalf Of Thomas Weidenmueller
>>Sent: Wednesday, May 04, 2005 7:16 AM
>>To: ReactOS Development List
>>Subject: Re: [ros-dev] gcc problem or not
>>
>>
>>Hartmut Birr wrote:
>>    
>>
>>>Hi,
>>>
>>>I was always the opinion  that the examination of a test condition 
>>>stops if the result can not change again. A test condition 
>>>      
>>>
>>like this:
>>    
>>
>>>if (pointer == NULL || pointer->member == 0)
>>>
>>>should never access pointer->member if pointer is zero. 
>>>      
>>>
>>Compared with 
>>    
>>
>>>the code above, it is possible that gcc build the result from the 
>>>right side of the OR statement. This may hit a page fault. 
>>>      
>>>
>>Is this a 
>>    
>>
>>>bug in gcc?
>>>      
>>>
>>It should definitely not dereference if it's NULL. The 
>>conditions should 
>>be checked from left to right in this case, no matter how much was 
>>optimized.
>>
>>    
>>
>
>To be safe, you might also check
>BadReadPtr(pointer,sizeof(struct_pointed_to)).  The pointer may be
>undefined, rather than NULL.
>
>Danny
>
>  
>
You are right, but I've still assumed that the pointer is zero or valid.
The real problem is, that gcc doesn't stop to validate an expression if
the result is determined and if the expression consist of simple
expressions which are combined with OR.

- Hartmut



More information about the Ros-dev mailing list