←back to thread

Introducing tmux-rs

(richardscollin.github.io)
857 points Jtsummers | 1 comments | | HN request time: 0.207s | source
1. sriku ◴[] No.44462931[source]
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).