Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Obsolete memory allocation in Move_Rows_Down, or bug? #1093

Open
xezon opened this issue Feb 8, 2024 · 0 comments
Open

Obsolete memory allocation in Move_Rows_Down, or bug? #1093

xezon opened this issue Feb 8, 2024 · 0 comments
Labels
investigate Investigation and careful discussion needed optimization

Comments

@xezon
Copy link
Contributor

xezon commented Feb 8, 2024

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);
@xezon xezon added investigate Investigation and careful discussion needed optimization labels Feb 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
investigate Investigation and careful discussion needed optimization
Projects
None yet
Development

No branches or pull requests

1 participant