r/shittyprogramming • u/Smellypuce2 • Jul 31 '18
Shitty RNG
int random_number()
{
int result;
return result;
}
Found in my own codebase and it gave me a good chuckle. It was never used and I can't remember what I was originally going to write. I stopped before actually writing the function out and this is what was left.
98
Upvotes
View all comments
Show parent comment
7
u/mort96 Jul 31 '18
The memory is getting allocated on the stack. Stack allocated memory generally contains garbage, not 0.
Even memory allocated by malloc often contains garbage; even though the pages the OS gives to the program are zeroed out,
mallocoften gives you a piece of memory which is re-used; your program hasfreed it, but the page hasn't been returned to the OS yet, somallocre-uses it.