Ask Your Question

Revision history [back]

is this code in modules/flann/src/miniflann.cpp a bug?

Using an experimental new static analysis technique we (GrammaTech) detected what may be a bug in createIndicesDists, miniflann.cpp:

static void createIndicesDists(OutputArray _indices, OutputArray _dists, 
                                       Mat& indices, Mat& dists, int rows, 
                                       int minCols, int maxCols, int dtype) 
        { 
            if( _indices.needed() ) 
            { 
                indices = _indices.getMat(); 
                if( !indices.isContinuous() || indices.type() != CV_32S || 
                    indices.rows != rows || indices.cols < minCols || indices.cols > maxCols ) 
                { 
                    if( !indices.isContinuous() ) 
                       _indices.release(); 
                    _indices.create( rows, minCols, CV_32S ); 
                    indices = _indices.getMat(); 
                } 
            } 
            else 
                indices.create( rows, minCols, CV_32S ); 

            if( _dists.needed() ) 
            { 
                dists = _dists.getMat(); 
                if( !dists.isContinuous() || dists.type() != dtype || 
                   dists.rows != rows || dists.cols < minCols || dists.cols > maxCols ) 
                { 
                    if( !indices.isContinuous() ) // HERE!  should this be 'dists'?
                        _dists.release(); 
                    _dists.create( rows, minCols, dtype ); 
                    dists = _dists.getMat(); 
                } 
            } 
            else 
                dists.create( rows, minCols, dtype ); 
        }

The block of code operating on _dists/dists appears to be a copy of the above block operating on _indices/indices, with all of the occurrences of _indices/indices changed to _dists/dists except the one noted in the "HERE!" comment. This inconsistency couid be intentional, but it is highly suspicious. Can anyone "in the know" confirm or deny that this is a bug?