Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 367db37d authored by Agata Cacko's avatar Agata Cacko Committed by Dmitry Kazakov

Fix Palette not checking columnsCount() for 0

This commit makes sure that Python won't crash from
setting columnCount() to 0 and adds check for columnCount()
being zero in some functions.

CID 248702
CID 248479
parent 0bf484f2
......@@ -50,7 +50,7 @@ int Palette::columnCount()
void Palette::setColumnCount(int columns)
{
if (d->palette)
if (d->palette && columns > 0)
d->palette->setColumnCount(columns);
}
......@@ -92,7 +92,9 @@ int Palette::colorsCountTotal()
Swatch *Palette::colorSetEntryByIndex(int index)
{
if (!d->palette) return new Swatch();
if (!d->palette || columnCount() == 0) {
return new Swatch();
}
int col = index % columnCount();
int row = (index - col) / columnCount();
return new Swatch(d->palette->getColorGlobal(col, row));
......@@ -100,7 +102,9 @@ Swatch *Palette::colorSetEntryByIndex(int index)
Swatch *Palette::colorSetEntryFromGroup(int index, const QString &groupName)
{
if (!d->palette) return new Swatch();
if (!d->palette || columnCount() == 0) {
return new Swatch();
}
int row = index % columnCount();
return new Swatch(d->palette->getColorGroup((index - row) / columnCount(), row, groupName));
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment