MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/ProgrammerHumor/comments/1w2m4qz/bugintroduceddebugging/p6wlkwa/?context=9999
r/ProgrammerHumor • u/ClipboardCopyPaste • 2d ago
120 comments sorted by
View all comments
344
Is the mistake that they're allocating 1 byte and storing in a pointer to an int which is 4 bytes?
157 u/atanasius 2d ago It's allowed to assign to a pointer if it's not dereferenced. Malloc always returns a valid pointer. 53 u/vishal340 2d ago but accessing it will be issue right? 39 u/backfire10z 2d ago Likely not. Malloc guarantees that the passed-in size is the minimum number of bytes it allocates, but not the maximum. You’d likely get some minimum sized chunk, somewhere between 16-32 bytes depending on the system as far as I understand it. 4 u/Deep-Piece3181 2d ago That’s an implementation detail it’s still 100% UB
157
It's allowed to assign to a pointer if it's not dereferenced. Malloc always returns a valid pointer.
53 u/vishal340 2d ago but accessing it will be issue right? 39 u/backfire10z 2d ago Likely not. Malloc guarantees that the passed-in size is the minimum number of bytes it allocates, but not the maximum. You’d likely get some minimum sized chunk, somewhere between 16-32 bytes depending on the system as far as I understand it. 4 u/Deep-Piece3181 2d ago That’s an implementation detail it’s still 100% UB
53
but accessing it will be issue right?
39 u/backfire10z 2d ago Likely not. Malloc guarantees that the passed-in size is the minimum number of bytes it allocates, but not the maximum. You’d likely get some minimum sized chunk, somewhere between 16-32 bytes depending on the system as far as I understand it. 4 u/Deep-Piece3181 2d ago That’s an implementation detail it’s still 100% UB
39
Likely not. Malloc guarantees that the passed-in size is the minimum number of bytes it allocates, but not the maximum. You’d likely get some minimum sized chunk, somewhere between 16-32 bytes depending on the system as far as I understand it.
4 u/Deep-Piece3181 2d ago That’s an implementation detail it’s still 100% UB
4
That’s an implementation detail it’s still 100% UB
344
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?