Skip to content

Mark intended integer division in double context

Fixes a problem detected by Coverity Scan.

Coverity Scan log (relevant part)

(...)

*** CID 241675: (UNINTENDED_INTEGER_DIVISION)
/zpool/projects/Devel/KDE/src/konsole/src/TerminalDisplay.cpp: 728
in Konsole::TerminalDisplay::drawCursor(QPainter &, const QRect &,
const QColor &, const QColor &, bool &)()

722 painter.setPen(cursorColor);
723 724 if (_cursorShape == Enum::BlockCursor) {
725 // draw the cursor outline, adjusting the area so that
726 // it is draw entirely inside 'rect'
727 int penWidth = qMax(1, painter.pen().width());

CID 241675: (UNINTENDED_INTEGER_DIVISION)
Dividing integer expressions "penWidth" and "2", and then converting
the integer quotient to type "double". Any remainder, or fractional
part of the quotient, is ignored.

728 painter.drawRect(cursorRect.adjusted(penWidth / 2 + 0.5,
729 penWidth / 2 + 0.5,
730 - penWidth / 2 - penWidth % 2 + 0.5,
731 - penWidth / 2 - penWidth % 2 + 0.5));
732 733 // draw the cursor body only when the widget has focus

/zpool/projects/Devel/KDE/src/konsole/src/TerminalDisplay.cpp: 729
in Konsole::TerminalDisplay::drawCursor(QPainter &, const QRect &,
const QColor &, const QColor &, bool &)()

723 724 if (_cursorShape == Enum::BlockCursor) {
725 // draw the cursor outline, adjusting the area so that
726 // it is draw entirely inside 'rect'
727 int penWidth = qMax(1, painter.pen().width());
728 painter.drawRect(cursorRect.adjusted(penWidth / 2 + 0.5,

CID 241675: (UNINTENDED_INTEGER_DIVISION)
Dividing integer expressions "penWidth" and "2", and then converting
the integer quotient to type "double". Any remainder, or fractional
part of the quotient, is ignored.

729 penWidth / 2 + 0.5,
730 - penWidth / 2 - penWidth % 2 + 0.5,
731 - penWidth / 2 - penWidth % 2 + 0.5));
732 733 // draw the cursor body only when the widget has focus
734 if (hasFocus()) {

(...)

Merge request reports