[Bug sanitizer/82802] Potential UBSAN error with pointer difference (32-bits mode)

marxin at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Thu Nov 2 08:21:00 GMT 2017


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

Martin Liška <marxin at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2017-11-02
                 CC|                            |dodji at gcc dot gnu.org,
                   |                            |dvyukov at gcc dot gnu.org,
                   |                            |jakub at gcc dot gnu.org,
                   |                            |kcc at gcc dot gnu.org,
                   |                            |marxin at gcc dot gnu.org,
                   |                            |mpolacek at gcc dot gnu.org
          Component|c                           |sanitizer
   Target Milestone|---                         |6.5
     Ever confirmed|0                           |1

--- Comment #1 from Martin Liška <marxin at gcc dot gnu.org> ---
Confirmed, there's small reproducer:

$ cat pr82802.c
int main()
{
  int *high = 0x80007800;
  int *low = 0x70018AAB;

  return high - low;
}


$ gcc pr82802.c -fsanitize=undefined -m32 && ./a.out 
pr82802.c: In function ‘main’:
pr82802.c:3:15: warning: initialization makes pointer from integer without a
cast [-Wint-conversion]
   int *high = 0x80007800;
               ^~~~~~~~~~
pr82802.c:4:14: warning: initialization makes pointer from integer without a
cast [-Wint-conversion]
   int *low = 0x70018AAB;
              ^~~~~~~~~~
pr82802.c:6:15: runtime error: signed integer overflow: -2147452928 -
1879149227 cannot be represented in type 'int'


More information about the Gcc-bugs mailing list