Ask Your Question

Revision history [back]

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

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?