This is the mail archive of the gcc-bugs@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]

[Bug c/63303] Pointer subtraction is broken when using -fsanitize=undefined


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63303

--- Comment #5 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
(In reply to mikulas from comment #4)
> ... and another related problem (try this on 32-bit system):
> 
> #include <stdio.h>
> #include <stdlib.h>
> 
> int main(void)
> {
>         short *a = malloc(0x50000000 * sizeof(short));
>         short *b = a + 0x50000000;
>         printf("%ld\n", (long)(b - a));
>         return 0;
> }
> 
> Here, the return value should be positive (0x50000000), but it is negative.
> IMHO, according to the C standard, this is program correct and positive
> result should be returned.

This testcase is invalid, you really can't have an object bigger than half of
the address space in C/C++, pointer difference is signed ptrdiff_t and if you
have larger object, you can't subtract arbitrary char pointers in it anymore.
If you need more than 2GB in a single array, just use 64-bit system.


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