Skip to content
New issue

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

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

Already on GitHub? # to your account

Bug with the maximum number of device types #190

Closed
martaisty opened this issue Aug 27, 2023 · 0 comments · Fixed by #191
Closed

Bug with the maximum number of device types #190

martaisty opened this issue Aug 27, 2023 · 0 comments · Fixed by #191

Comments

@martaisty
Copy link
Contributor

The bug:

The configured maximum number of device types _maxDevicesTypesNb doesn't represent the actual maximum of device types you can add. The exact number of devices is always one less than the configured value.

Root of the bug:

The condition that checks if it is possible to add more devices is incorrect.

The condition:

if (_devicesTypesNb + 1 >= _maxDevicesTypesNb) {
return;
}

Initial values:

_devicesTypesNb(0), \
_maxDevicesTypesNb(maxDevicesTypesNb), \
_devicesTypes(new HABaseDeviceType*[maxDevicesTypesNb]), \

Simple example to understand why it's incorrect

Let's say I want only 1 device type, so I pass maxDevicesTypesNb = 1 to the HAMqtt's constructor. Then I won't be able to add the device due to the incorrect if-check above. 0 + 1 >= 1 => true. The same is true for other numbers, having a maximum set to 7, you can add only 6 devices.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants