Skip to content

Obsolete memory allocation in Move_Rows_Down, or bug? #1093

Open
@xezon

Description

@xezon
int Move_Rows_Down(_ListboxData *data, int row)
{
    int size = sizeof(_ListEntryRow) * (data->m_endPos - row);
    char *buf = new char[size];
    memcpy(buf, &data->m_listData[row], size);
    memcpy(&data->m_listData[row + 1], buf, size);
    delete[] buf;
...
}

It allocates a buf, copies data->m_listData[row] into buf, and copies buf into data->m_listData[row + 1].

This makes no sense. It can copy data->m_listData[row] directly into data->m_listData[row + 1]:

memcpy(&data->m_listData[row + 1], &data->m_listData[row], size);

Alternatively, perhaps this meant to swap the rows? In that case one would need to add as 2nd copy step:

memcpy(&data->m_listData[row], &data->m_listData[row + 1], size);

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions