[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Bug-ocrad] Bug in the Profile::iscpit loop
From: |
Antonio Diaz Diaz |
Subject: |
Re: [Bug-ocrad] Bug in the Profile::iscpit loop |
Date: |
Wed, 15 Nov 2006 16:30:12 +0100 |
User-agent: |
Mozilla/5.0 (X11; U; Linux i586; en-US; rv:1.7.12) Gecko/20050923 |
Georgi Demirchev wrote:
I saw a bug in Profile::iscpit function, I've seen it only once and and is
hard to be sumilated again:
Thank you for this bug report. I have fixed it. Please, apply the
attached patch.
Regards,
Antonio.
--- ../old_src/profile.cc 2006-08-22 15:55:58.000000000 +0200
+++ profile.cc 2006-11-15 16:20:30.000000000 +0100
@@ -349,10 +349,12 @@
{
if( _limit < 0 ) initialize();
if( samples() < 5 || cpos < 25 || cpos > 75 ) return false;
- int th = ( mean() < 2 ) ? 2 : mean();
- int imin = -1, mid = ( ( samples() - 1 ) * cpos ) / 100;
+ const int mid = ( ( samples() - 1 ) * cpos ) / 100;
+ const int iend = std::min( samples() / 4, std::min( mid, samples() -
mid ) );
+ const int th = ( ( mean() < 2 ) ? 2 : mean() );
+ int imin = -1;
- for( int i = 0; i < samples() / 4; ++i )
+ for( int i = 0; i < iend; ++i )
{
if( data[mid+i] < th ) { imin = mid + i; break; }
if( data[mid-i-1] < th ) { imin = mid - i - 1; break; }
@@ -507,10 +509,11 @@
if( _limit < 0 ) initialize();
if( samples() < 5 || cpos < 25 || cpos > 75 ) return false;
const int mid = ( ( samples() - 1 ) * cpos ) / 100;
+ const int iend = std::min( samples() / 4, std::min( mid, samples() -
mid ) );
int th = std::max( 2, std::min( mean(), _limit / 3 ) );
int imax = -1;
- for( int i = 0; i < samples() / 4; ++i )
+ for( int i = 0; i < iend; ++i )
{
if( data[mid+i] > th ) { imax = mid + i; break; }
if( data[mid-i-1] > th ) { imax = mid - i - 1; break; }
@@ -518,7 +521,7 @@
if( imax < 0 && mean() == 0 )
{
--th;
- for( int i = 0; i < samples() / 4; ++i )
+ for( int i = 0; i < iend; ++i )
{
if( data[mid+i] > th ) { imax = mid + i; break; }
if( data[mid-i-1] > th ) { imax = mid - i - 1; break; }