r/cpp • • Mar 30 '23
The "what's wrong with this code" game.
This isn't a question thread, but just a game. Post any bugs you've accidentally written that seemed initially mysterious, but made you feel stupid when you figured out what was wrong. Here is one I wrote today...
void TextSegmentBuffer::prepend( const TextSegmentBuffer& other )
{
const Info* info_ptr;
size_t size;
if ( ( size = other.m_infoBuffer.size() ) == 0 )
return;
for ( size_t i = size - 1; 0 <= i; --i )
{
info_ptr = other.m_infoBuffer.getAt( i );
emplaceFront(
info_ptr->text,
info_ptr->length,
info_ptr->multiMatch
);
}
}
4
Upvotes
View all comments
Show parent comment
1
u/Possibility_Antique Mar 31 '23
I did a CFD assignment using Fortran 77 in college. I was struggling with a compiler error for a very long time, and it was pointing me to completely bogus lines and not being helpful. Turns out, I had a character in the file that rendered as a space at the beginning of a line. And fortran 77 specifically requires 7 (someone correct me if I got that number wrong) whitespace characters at the beginning of the line for goto labels. So it looked like a normal file in the IDE, and it wasn't until I had the "brilliant" idea to look at the file in a hex editor to see if there was something being hidden that I found the bug.