# Suspicous code in kdelibs-3.5.2

Cristian Tibirna tibirna at kde.org
Sat Apr 8 14:59:59 BST 2006

On 5 April 2006 10:26, Christoph Bartoschek wrote:
> - kdeprint/management/kxmlcommanddlg.cpp:620
>
> If opt becomes NULL in line 573 and the switch in line 585 selects the
> default case, then line 620 crashes.

That code can't crash. The "opt" pointer will always get initialized.
m_type->currentItem() (used to initialize "type", the switch variable) must
have values in the interval [0,4] \in I (the multitude of integer numbers)
and gets augmented by DrBase::String. Thus, the only possible values in the
switch are those checked.

If I had a "programming-by-contract" frame in KDE, I would have added an
assertion in development-mode. Without one, this would mean adding useless
translatable strings (for a KMessageBox::error) and break too many freeze
rules.

> -----------------------------------------------------------------
> Cases from switch statements that fall through in some cases but
> do not have a fall through comment as in most such cases.
> ------------------------------------------------------------------
>
[cut]
> - kdeprint/management/kmwname.cpp:66
What a "fall through comment is"?  That code is correct.

> - kdeprint/kprintprocess.cpp:78
I can't follow thoroughly the logic of that code, to say if fall-through is
OK. I think it is. Wouldn't know what comment to put either.

[cut]

Thanks a lot for the excellent diagnoses. Better worry than sorry ;-)

--
Cristian Tibirna
KDE developer .. tibirna at kde.org .. http://www.kde.org