Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

In "Interesting bugs / Bug 1",

  I walked through the code again. Inside of the Rust function (*c).bar has a valid address, like 0x60302764, but out the function, the value received from the calling C code was 0x2764.

  ...

  That’s right, the C code was using the implicit declaration which is:
   
  int get_addr();
  
  That explains why the value was incorrect! The C compiler was thinking a 4 byte int was returned not an 8 byte pointer. So the top 4 bytes were being truncated or ignored.
That's weird as an explanation. 0x60302764 is 4 bytes and 0x2764 is 2 bytes. Why would an address get truncated to 2 bytes? Is int 2-bytes according to any intermediate compilation stage? (Been at least 25 years since I saw int be 2 bytes, if ever).


Consider applying for YC's Fall 2026 batch! Applications are open till July 27.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: