On Tuesday, October 29, 2013 01:21:08 Jiergir Ogoerg wrote:
> Hi,
> There's an enum:
> 
> //==> code
> enum TableState
>     {
>         UnsupportedLocale,
>         EmptyTable,
>         UnknownSystemComposeDir,
>         MissingComposeFile,
>         NoErrors
>     };
> //<== code
> 
> and this:
> 
> //==> code
> bool cleanState() const { return ((m_state & NoErrors) == NoErrors); }
> //<== code
> 
> Shouldn't the latter be ?:
> //==> code
> bool cleanState() const { return (m_state == NoErrors); }
> //<== code
> 
> Found at
> QTSRC/qtbase/src/plugins/platforminputcontexts/compose/generator/qtablegene
> rator.h

According to the standard, they are equivalent, since reading a value from an 
enum object that does have one of the declared enum values results in undefined 
behaviour. That said, we're violating that in many places in Qt, e.g. in 
QFlags, so it might be that the code in question also abuses m_state that way. 
in that case, the existing code would be more robust, but faces the compiler 
optimising away the & NoErrors due to the reason mentioned above.

The correct fix is to check if m_state takes values not in TableState values 
and if so, change its type to int or uint, otherwise, apply your suggestion.

HTH,
Marc


Thanks,
Marc
_______________________________________________
Development mailing list
[email protected]
http://lists.qt-project.org/mailman/listinfo/development

Reply via email to