Ask Your Question
1

Possible bug in modules/highgui/src/window_gtk.cpp

asked 2017-09-01 16:37:47 -0600

Using an experimental new static analysis technique, we (GrammaTech) identified what appears to be a bug in cvImageWidget_get_preferred_height in modules/highgui/src/window_gtk.cpp:

 #if defined (GTK_VERSION3) 
        static void 
        cvImageWidget_get_preferred_width (GtkWidget *widget, gint *minimal_width, gint *natural_width) 
        { 
          g_return_if_fail (widget != NULL); 
          g_return_if_fail (CV_IS_IMAGE_WIDGET (widget)); 
          CvImageWidget * image_widget = CV_IMAGE_WIDGET( widget ); 

          if(image_widget->original_image != NULL) { 
            *minimal_width = (image_widget->flags & CV_WINDOW_AUTOSIZE) != CV_WINDOW_AUTOSIZE ? 
              gdk_window_get_width(gtk_widget_get_window(widget)) : image_widget->original_image->cols; 
          } 
          else { 
            *minimal_width = 320; 
          } 

          if(image_widget->scaled_image != NULL) { 
            *natural_width = *minimal_width < image_widget->scaled_image->cols ? 
              image_widget->scaled_image->cols : *minimal_width; 
          } 
          else { 
            *natural_width = *minimal_width; 
          } 
        } 

        static void 
        cvImageWidget_get_preferred_height (GtkWidget *widget, gint *minimal_height, gint *natural_height) 
        { 
          g_return_if_fail (widget != NULL); 
          g_return_if_fail (CV_IS_IMAGE_WIDGET (widget)); 
          CvImageWidget * image_widget = CV_IMAGE_WIDGET( widget ); 

          if(image_widget->original_image != NULL) { 
            *minimal_height = (image_widget->flags & CV_WINDOW_AUTOSIZE) != CV_WINDOW_AUTOSIZE ? 
              gdk_window_get_height(gtk_widget_get_window(widget)) : image_widget->original_image->rows; 
          } 
          else { 
            *minimal_height = 240; 
          } 

          if(image_widget->scaled_image != NULL) { 
            *natural_height = *minimal_height < image_widget->scaled_image->rows ? 
              image_widget->scaled_image->cols : *minimal_height; // HERE! should "cols" be "rows"?
                      } 
          else { 
            *natural_height = *minimal_height; 
          } 
        } 

        #else 
                    ...

This "height" function appears to be a copy of the above "width" function with a systematic set of height/width-related changes applied, but it looks like the occurrence of "cols" on the line with the "HERE!" comment was missed. Can someone familiar with this code confrim/deny that this is a bug?

edit retag flag offensive close merge delete

Comments

1

it seems copy/paste bug cc @mshabunin

sturkmen gravatar imagesturkmen ( 2017-09-01 17:00:48 -0600 )edit
1

Yes, looks like a bug. You can file an issue to our bug tracker or create a pull request with the fix.

mshabunin gravatar imagemshabunin ( 2017-09-02 01:28:44 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
2

answered 2017-09-03 17:48:51 -0600

Factoring?

// a couple of suitable typedefs...

        static void 
        cvImageWidget_get_preferred_dimension (GtkWidget *widget, gint *minimal, gint *natural,
                                               GtkWindowDimensionFn_t win_get_dim,
                                               CvImageWidgetDimMember image_dim_member
                                               gint default_min) 
        { 
          g_return_if_fail (widget != NULL); 
          g_return_if_fail (CV_IS_IMAGE_WIDGET (widget)); 
          CvImageWidget * image_widget = CV_IMAGE_WIDGET( widget ); 

          if(image_widget->original_image != NULL) { 
            *minimal = (image_widget->flags & CV_WINDOW_AUTOSIZE) != CV_WINDOW_AUTOSIZE ? 
              (*win_get_dim)(gtk_widget_get_window(widget)) : image_widget->original_image->*image_dim_member; 
          } 
          else { 
            *minimal = default_min; 
          } 

          if(image_widget->scaled_image != NULL) { 
            *natural = *minimal_width < image_widget->scaled_image->*image_dim_member ? 
              image_widget->scaled_image->*image_dim_member : *minimal; 
          } 
          else { 
            *natural = *minimal; 
          } 
        } 

static void 
        cvImageWidget_get_preferred_width (GtkWidget *widget, gint *minimal_width, gint *natural_width) 
        {
            cvImageWidget_get_preferred_dimension( widget, minimal_width, natural_width,
                                                   gdk_window_get_width, &CvImageWidget::cols,
                                                   320 );
        }

static void 
        cvImageWidget_get_preferred_height (GtkWidget *widget, gint *minimal_height, gint *natural_height) 
        {
            cvImageWidget_get_preferred_dimension( widget, minimal_height, natural_height,
                                                   gdk_window_get_height, &CvImageWidget::rows,
                                                   240 );
        }
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2017-09-01 16:37:47 -0600

Seen: 268 times

Last updated: Sep 03 '17