← Back to team overview

kicad-developers team mailing list archive

Re: Questionable code

 

So I haven't been active for the last few months but I have been
running coverity weekly at least ;)

I noticed this one three months ago....

4bool PNS_DIFF_PAIR_PLACER::tryWalkDp( PNS_NODE* aNode, PNS_DIFF_PAIR
&aPair, bool aSolidsOnly )
245{
246    PNS_DIFF_PAIR best;
247    double bestScore = 100000000000000.0;
248
assignment: Assigning: attempt = 0.
incr: Incrementing attempt. The value of attempt is now 1.
249    for( int attempt = 0; attempt <= 1; attempt++ )
250    {
251        PNS_DIFF_PAIR p;
252        PNS_NODE *tmp = m_currentNode->Branch();
253
254        bool pfirst = attempt % 2 ? true : false;

between: At condition attempt / 2, the value of attempt must be between 0 and 1.

dead_error_condition: The condition attempt / 2 cannot be true.

CID 106366 (#1 of 1): Logically dead code (DEADCODE)dead_error_line:
Execution cannot reach the expression true inside this statement:
wind_cw = ((attempt / 2) ? ....
255        bool wind_cw = attempt / 2 ? true : false;
256
257        if( attemptWalk ( tmp, &aPair, p, pfirst, wind_cw, aSolidsOnly ) )
258        {



It only loops to 1 but it does a divide 2.......so the flag will never
set as 0/2 and 1/2 are both 0. Not sure what was intended.


References