Hacker News new | past | comments | ask | show | jobs | submit login

Reading from uninitialized memory in C seems to be a bad idea:

http://blog.frama-c.com/index.php?post/2013/03/13/indetermin...




I didn't read all that, but it seems like the issue there is that, if the compiler sees you are reading from uninitialised memory, then it can effectively 'choose' a value for the contents of that memory to suit it's optimisation purposes. Is that right?

If so, then this isn't actually a problem in the case of sparse sets. With sparse sets we don't care what is in the uninitialised memory and if the compiler wants to get tricky and choose values for this memory (which I don't think actually applies in this context) that doesn't change the correctness of the data structure..


If you read it, you'll see that things are much worse than that.


Ok, yes. Reading to the end of stuff is a good thing. :)


> “Xoring an uninitialized variable with whatever other source of entropy you already have cannot hurt”, the conventional thinking goes. Conventional thinking is wrong. Your typical modern compiler deletes the code that gathers the original entropy, since it is only going to be xored with an uninitialized variable.

The sparse array in the OP can't be optimized in this way at compile time.


You should be able to avoid those issue if you use a volotile variable.


It only concerns automatic objects though, right?




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

Search: