MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/ProgrammerHumor/comments/1w2m4qz/bugintroduceddebugging/p6tn2dl/?context=3
r/ProgrammerHumor • u/ClipboardCopyPaste • 2d ago
120 comments sorted by
View all comments
345
Is the mistake that they're allocating 1 byte and storing in a pointer to an int which is 4 bytes?
117 u/mckenzie_keith 2d ago De-referenced a pointer after freeing it. But the joke here is that the bug was not in the original code. 15 u/AdBrave2400 2d ago I know 0 u/WisestAirBender 2d ago The original code wasn't returning anything though. Isn't that a problem 18 u/mckenzie_keith 2d ago No. main() doesn't need to return anything. -6 u/critical_patch 2d ago AFAIK technically it’s “undefined behavior” and will compile just fine 17 u/MegaIng 2d ago main specifically is allowed to not return anything (the same way it's the one function that is allowed to never return) 0 u/Original-Ad-8737 2d ago I learned recently that there is a kind of implicit return... It will automatically assume that the return value is the last used variable or something like that. Dont know specifics but i was weirded out why the compiler wasnt complaining about missing returns in some methods... 1 u/mckenzie_keith 1d ago Only in main() as far as I know. All others the compiler should warn you.
117
De-referenced a pointer after freeing it. But the joke here is that the bug was not in the original code.
15 u/AdBrave2400 2d ago I know 0 u/WisestAirBender 2d ago The original code wasn't returning anything though. Isn't that a problem 18 u/mckenzie_keith 2d ago No. main() doesn't need to return anything. -6 u/critical_patch 2d ago AFAIK technically it’s “undefined behavior” and will compile just fine 17 u/MegaIng 2d ago main specifically is allowed to not return anything (the same way it's the one function that is allowed to never return) 0 u/Original-Ad-8737 2d ago I learned recently that there is a kind of implicit return... It will automatically assume that the return value is the last used variable or something like that. Dont know specifics but i was weirded out why the compiler wasnt complaining about missing returns in some methods... 1 u/mckenzie_keith 1d ago Only in main() as far as I know. All others the compiler should warn you.
15
I know
0
The original code wasn't returning anything though. Isn't that a problem
18 u/mckenzie_keith 2d ago No. main() doesn't need to return anything. -6 u/critical_patch 2d ago AFAIK technically it’s “undefined behavior” and will compile just fine 17 u/MegaIng 2d ago main specifically is allowed to not return anything (the same way it's the one function that is allowed to never return)
18
No. main() doesn't need to return anything.
-6
AFAIK technically it’s “undefined behavior” and will compile just fine
17 u/MegaIng 2d ago main specifically is allowed to not return anything (the same way it's the one function that is allowed to never return)
17
main specifically is allowed to not return anything (the same way it's the one function that is allowed to never return)
main
I learned recently that there is a kind of implicit return...
It will automatically assume that the return value is the last used variable or something like that.
Dont know specifics but i was weirded out why the compiler wasnt complaining about missing returns in some methods...
1 u/mckenzie_keith 1d ago Only in main() as far as I know. All others the compiler should warn you.
1
Only in main() as far as I know. All others the compiler should warn you.
345
u/AdBrave2400 2d ago
Is the mistake that they're allocating 1 byte and storing in a pointer to an int which is 4 bytes?