Comment #4 on issue 269 by [email protected]: comparison and difference on unrelated pointers
http://code.google.com/p/address-sanitizer/issues/detail?id=269

When I used that feature with Insure++ (a long time ago), I almost never
saw any false positives. The only false positive that I remember, what
a program that was comparing 2 unrelated pointers both in the stack, to
find out in which direction the stack was growing. But that's a fairly
odd and rare thing to do in the first place.  I think it was in the
only false positive I ever saw was in this function in Vim source code
(in vim/src/os_unix.c):

 696 static int stack_grows_downwards;
 697
 698 /*
 699  * Find out if the stack grows upwards or downwards.
 700  * "p" points to a variable on the stack of the caller.
 701  */
 702     static void
 703 check_stack_growth(p)
 704     char        *p;
 705 {
 706     int         i;
 707
 708     stack_grows_downwards = (p > (char *)&i);
 709 }

...

3053     int                 i;
3054
3055     check_stack_growth((char *)&i);

The comparison at line 708 is undefined as it is true
if the stack is growing in one direction or false if
the stack is growing in the other direction. That's
precisely what that function is checking, so in that
case it was a false positive.

Thinking about it, it should not complain when checking in both
directions as the pointer comparison is then valid.  Example:

int *p;
int a[10];
...
if (p >= &a[0] && p < &a[10])
{
  /* This always OK */
  ...
}

if (p >= &a[0])
{
  /* This has undefined behaviour if p and &a[0] are unrelated pointers */
}


--
You received this message because this project is configured to send all issue notifications to this address.
You may adjust your notification preferences at:
https://code.google.com/hosting/settings

--
You received this message because you are subscribed to the Google Groups 
"address-sanitizer" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to