0

getenv("USER") returns two different addresses when called from two different functions.

0x7fff60e15e79 0x60e15e79

So in the second case the 7fff part is missing . This is leading to a crash when I try to print the string in the second case . Does anyone has any idea why this might be happening?

Sumit Das
  • 1,007
  • 9
  • 17
  • What operating system, what language, what compiler? Can you post the 2 functions? And how are you determining the addresses? – Greycon Sep 05 '14 at 14:36
  • i'm using %p with printf . Actually I think I figured out the problem . In the second case , stdlib is not included . But then I'm surprised how did getenv() work at all – Sumit Das Sep 05 '14 at 14:51
  • 2
    @SumitDas If you're not including the function prototype for `getenv()`, then the compiler assumes that it returns an `int` (and should produce a compiler warning as well, which you should pay attention to...). My guess is you're on a system where a `char *` is 64-bits and an `int` is 32-bits... – twalberg Sep 05 '14 at 14:56
  • @twalberg:Thanks for your input . I verified that char* is 8 bytes and int is 4 bytes . – Sumit Das Sep 05 '14 at 15:39

0 Answers0