bloguetronica / cp2130-conf

CP2130 Configurator (cp2130-conf) is an application that can be used to configure CP2130 devices, including VID, PID, as well as other descriptors. Most importantly, the application allows you to configure pin functions and states.
GNU General Public License v3.0
1 stars 1 forks source link

Severe bugs in ConfiguratorWindow::getEditedConfiguration(), where the bitmap fields are not read properly #45

Closed samuelfmlourenco closed 1 week ago

samuelfmlourenco commented 2 weeks ago

Inside configuratorwindow.cpp, lines 601 to 604, in getEditedConfiguration(), the values should be treated as base-16. Unfortunately, this went unnoticed. Currently we have:

void ConfiguratorWindow::getEditedConfiguration()
{
    ...
    editedConfig_.pinconfig.sspndlvl = static_cast<quint16>(ui->lineEditSuspendLevel->text().toUInt());
    editedConfig_.pinconfig.sspndmode = static_cast<quint16>(ui->lineEditSuspendMode->text().toUInt());
    editedConfig_.pinconfig.wkupmask = static_cast<quint16>(ui->lineEditResumeMask->text().toUInt());
    editedConfig_.pinconfig.wkupmatch = static_cast<quint16>(ui->lineEditResumeMatch->text().toUInt());
    ...
}

The values read from the line edit boxes are represented in hexadecimal, but they are being processed as if they were decimal. This obviously leads to severe conversion errors. The fix is simple:

void ConfiguratorWindow::getEditedConfiguration()
{
    ...
    editedConfig_.pinconfig.sspndlvl = static_cast<quint16>(ui->lineEditSuspendLevel->text().toUInt(nullptr, 16));
    editedConfig_.pinconfig.sspndmode = static_cast<quint16>(ui->lineEditSuspendMode->text().toUInt(nullptr, 16));
    editedConfig_.pinconfig.wkupmask = static_cast<quint16>(ui->lineEditResumeMask->text().toUInt(nullptr, 16));
    editedConfig_.pinconfig.wkupmatch = static_cast<quint16>(ui->lineEditResumeMatch->text().toUInt(nullptr, 16));
    ...
}
samuelfmlourenco commented 1 week ago

Fixed in version 3.0.