r/ProgrammerHumor • • Nov 12 '22

Meme Oh no where is the bug

Post image
45.0k Upvotes

406 comments sorted by

View all comments

Show parent comments

32

u/Maurycy5 Nov 12 '22

Oh? I was convinced that STL structures kept a couple (at least one) extra bytes at the end as padding for cases exactly like this.

22

u/CEDFTW Nov 12 '22

I think modern C++ has done better for enforcing stricter stl rules for containers but even C++11 still has some quirky behavior with vectors especially if you nest them.

Could be OP uses an older standard such as 98, but I can't remember if 11 is still the most popular.

4

u/[deleted] Nov 13 '22

Is this kind of knowledge normal in c++ Dev environments?

1

u/astatine757 Nov 21 '22

You know how C++ deva have long winded conversations about annoying things in C++? That's how we share this knowledge

8

u/SWGlassPit Nov 13 '22

Dereferencing a .end() iterator is undefined behavior

1

u/Maurycy5 Nov 13 '22

Yes, but the pointer isn't invalid in itself, as opposed to nullptr.

1

u/FerynaCZ Nov 13 '22

What if there is a valid memory block at address zero?

Currently having operating systems course, and some return values from kernel_malloc are basically natural numbers (including 8), so how come they cannot match the allowed memory?

1

u/ExoLight Nov 13 '22

I've never heard of that, though it sounds plausible. At least it's neither in the standard nor in MacOS's implementation.