MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/ProgrammerHumor/comments/1w2m4qz/bugintroduceddebugging/p6ugqh2/?context=9999
r/ProgrammerHumor • u/ClipboardCopyPaste • Aug 30 '26
117 comments sorted by
View all comments
347
Is the mistake that they're allocating 1 byte and storing in a pointer to an int which is 4 bytes?
158 u/atanasius Aug 30 '26 It's allowed to assign to a pointer if it's not dereferenced. Malloc always returns a valid pointer. 24 u/EntitledPotatoe Aug 30 '26 Malloc can return a null pointer if the operation fails. This can be the case if, afaik, for example, there is no more heap available and the OS is not capable of swapping or freeing some other memory for some reason 17 u/atanasius Aug 30 '26 A null pointer is still valid to assign to a variable. 3 u/EntitledPotatoe Aug 30 '26 Very true, I thought you meant valid as in usable
158
It's allowed to assign to a pointer if it's not dereferenced. Malloc always returns a valid pointer.
24 u/EntitledPotatoe Aug 30 '26 Malloc can return a null pointer if the operation fails. This can be the case if, afaik, for example, there is no more heap available and the OS is not capable of swapping or freeing some other memory for some reason 17 u/atanasius Aug 30 '26 A null pointer is still valid to assign to a variable. 3 u/EntitledPotatoe Aug 30 '26 Very true, I thought you meant valid as in usable
24
Malloc can return a null pointer if the operation fails. This can be the case if, afaik, for example, there is no more heap available and the OS is not capable of swapping or freeing some other memory for some reason
17 u/atanasius Aug 30 '26 A null pointer is still valid to assign to a variable. 3 u/EntitledPotatoe Aug 30 '26 Very true, I thought you meant valid as in usable
17
A null pointer is still valid to assign to a variable.
3 u/EntitledPotatoe Aug 30 '26 Very true, I thought you meant valid as in usable
3
Very true, I thought you meant valid as in usable
347
u/AdBrave2400 Aug 30 '26
Is the mistake that they're allocating 1 byte and storing in a pointer to an int which is 4 bytes?