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

60 comments sorted by

View all comments

Show parent comments

0

u/[deleted] Mar 31 '23

[deleted]

1

u/[deleted] Apr 01 '23 edited Apr 01 '23

Yeah that's what I mean. If you ask garbage questions you get garbage answers.

Like to be blunt, what does it even mean to ask "Does fragmentation only happen inside the process?"

I can sympathize with people who don't speak English natively, but for those who are able to ask clear and precise technical questions, ChatGPT is an absolutely incredible resource.

As for your specific question, yes there are syscall versions of malloc that OS's, particularly Linux and the BSD family of OS's use (Windows works differently). So it's not exactly wrong to refer to these in the context of the answer it gave you.

0

u/[deleted] Apr 01 '23

[deleted]

1

u/[deleted] Apr 01 '23

I'm sorry it didn't work for you.