Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*.app
*.user
*.rej
.cache

moc_*.cpp
ui_*.h
Expand All @@ -15,9 +16,8 @@ qrc_*.cpp

rc_price_list.py
CPackConfig.cmake

configure.sh
configure.bat
CMakeUserPresets.json
compile_commands.json

bin/
lib/
Expand Down
2 changes: 1 addition & 1 deletion docs/CHANGES_2_4.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ General:

Bugfixes:
-------------
*
* Fix undefined behaviour (invalid int-to-enum cast) in AbstractTableElementPrivate::fillConstraints, detected by UBSAN.

New features:
-------------
Expand Down
16 changes: 9 additions & 7 deletions src/KDReports/KDReportsAbstractTableElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,15 @@ void KDReports::AbstractTableElementPrivate::fillConstraints(QTextTableFormat *t
constraints.reserve(m_constraints.size());
for (const auto &c : m_constraints) {
QTextLength length; // Variable by default
switch (c.unit) {
case Millimeters:
length = QTextLength(QTextLength::FixedLength, mmToPixels(c.width));
break;
case Percent:
length = QTextLength(QTextLength::PercentageLength, c.width);
break;
if (c.unit.has_value()) {
switch (*c.unit) {
case Millimeters:
length = QTextLength(QTextLength::FixedLength, mmToPixels(c.width));
break;
case Percent:
length = QTextLength(QTextLength::PercentageLength, c.width);
break;
}
}
constraints.append(length);
}
Expand Down
9 changes: 2 additions & 7 deletions src/KDReports/KDReportsAbstractTableElement.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

#include "KDReportsElement.h"
#include "KDReportsUnit.h"
#include <optional>

QT_BEGIN_NAMESPACE
template<typename T>
Expand Down Expand Up @@ -105,16 +106,10 @@ class KDREPORTS_EXPORT AbstractTableElement : public Element
*/
QFont defaultFont(bool *isSet) const;

enum // separate because we don't want "Variable" in other uses of Unit
{
Variable = Unit::Percent + 1 /// < no constraint, \since 2.3
};

struct ColumnConstraint
{
ColumnConstraint()
: width(0)
, unit(static_cast<Unit>(Variable))
{
}
ColumnConstraint(qreal w, Unit u)
Expand All @@ -123,7 +118,7 @@ class KDREPORTS_EXPORT AbstractTableElement : public Element
{
}
qreal width;
Unit unit;
std::optional<Unit> unit;
};

/**
Expand Down