Bug in the Profile::iscpit loop

View: New views
2 Messages — Rating Filter:   Alert me  

Bug in the Profile::iscpit loop

by Georgi Demirchev :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Dear Mr. Diaz,

I saw a bug in Profile::iscpit function, I've seen it only once and and is
hard to be sumilated again:

The function was invoked with cpos = 25, data member had 48 elements. Inside
the loop, where:

...
if( data[mid-i-1] < th ) { imin = mid - i - 1; break; }
...

and when mid = 11, i = 11, the -1st element was referenced.

Kind regards,
Georgi
_______________________________________________
Bug-ocrad mailing list
Bug-ocrad@...
http://lists.gnu.org/mailman/listinfo/bug-ocrad

Re: Bug in the Profile::iscpit loop

by Bugzilla from ant_diaz@teleline.es :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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; }


_______________________________________________
Bug-ocrad mailing list
Bug-ocrad@...
http://lists.gnu.org/mailman/listinfo/bug-ocrad