Date: prev next · Thread: first prev next last
2012 Archives by date, by thread · List index


Hi Mat,

15.01.2012 03:29, Mat M пишет:
Hello

Le Sat, 14 Jan 2012 16:00:31 +0100, julien2412 <serval2412@yahoo.fr> a
écrit:

Hello,

cppcheck reported this :
core/vcl/generic/fontmanager/fontconfig.cxx
196 duplicateExpression style Same expression on both sides of '-'

class SortFont : public ::std::binary_function< const FcPattern*, const
FcPattern*, bool >
{
public:
bool operator()(const FcPattern *a, const FcPattern *b)
{
int comp = compareFontNames(a, b);
if (comp != 0)
return comp < 0;

int nVersionA=0, nVersionB=0;

bool bHaveA = FcPatternGetInteger(a, FC_FONTVERSION, 0,
&nVersionA) == FcResultMatch;
bool bHaveB = FcPatternGetInteger(b, FC_FONTVERSION, 0,
&nVersionB) == FcResultMatch;

if (bHaveA && bHaveB)
return nVersionA > nVersionB;

196: return bHaveA - bHaveA;<--- Same expression on both sides of
'-'.
}
};

If we follow the same logic as the function compareFontNames defined some
lines above in the same file :
int compareFontNames(const FcPattern *a, const FcPattern *b)
{
FcChar8 *pNameA=NULL, *pNameB=NULL;

bool bHaveA = FcPatternGetString(a, FC_FAMILY, 0, &pNameA) ==
FcResultMatch;
bool bHaveB = FcPatternGetString(b, FC_FAMILY, 0, &pNameB) ==
FcResultMatch;

if (bHaveA && bHaveB)
return strcmp((const char*)pNameA, (const char*)pNameB);

return bHaveA - bHaveB;
}

it seems it should be :
return bHaveA - bHaveB;

Any idea ?

Subtracting booleans ??? Is there some magic here ?
Moreover, if we state that boolean difference returns a boolean, is
there an automatic cast, as the function should return an int ?

AFAIK in arithmetic bools are concerted to int so that true->1 and false->0.
Then, the result is converted back to bool (because the function returns bool) so that 0->false and 'any other value'->true.

So "return bool1 - bool2" can be replaced with not-so-magic "return bool1 != bool2", right?

By the way, the author of the code is Caolan, let's ask him. :)

Ivan


Context


Privacy Policy | Impressum (Legal Info) | Copyright information: Unless otherwise specified, all text and images on this website are licensed under the Creative Commons Attribution-Share Alike 3.0 License. This does not include the source code of LibreOffice, which is licensed under the Mozilla Public License (MPLv2). "LibreOffice" and "The Document Foundation" are registered trademarks of their corresponding registered owners or are in actual use as trademarks in one or more countries. Their respective logos and icons are also subject to international copyright laws. Use thereof is explained in our trademark policy.