Merge from mainline.
authorPaul Eggert <eggert@cs.ucla.edu>
Sun, 13 Mar 2011 17:28:15 +0000 (10:28 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Sun, 13 Mar 2011 17:28:15 +0000 (10:28 -0700)
src/ChangeLog
src/gtkutil.c
src/image.c
src/xgselect.c

index 1bc1e11..e840bb3 100644 (file)
@@ -1,5 +1,40 @@
 2011-03-13  Paul Eggert  <eggert@cs.ucla.edu>
 
+       Fix more problems found by GCC 4.5.2's static checks.
+
+       * gtkutil.c (xg_get_pixbuf_from_pixmap): Add cast from char *
+       to unsigned char * to avoid compiler diagnostic.
+       (xg_free_frame_widgets): Make it clear that a local variable is
+       needed only if USE_GTK_TOOLTIP.
+       (gdk_window_get_screen): Make it clear that this macro is needed
+       only if USE_GTK_TOOLTIP.
+       (int_gtk_range_get_value): New function, which avoids a diagnostic
+       from gcc -Wbad-function-cast.
+       (xg_set_toolkit_scroll_bar_thumb): Use it.
+       (xg_tool_bar_callback, xg_tool_item_stale_p): Rewrite to avoid
+       diagnostic from gcc -Wbad-function-cast.
+       (get_utf8_string, xg_get_file_with_chooser):
+       Rename locals to avoid shadowing.
+       (create_dialog): Move locals to avoid shadowing.
+
+       * xgselect.c (xg_select): Remove unused var.
+
+       * image.c (four_corners_best): Mark locals as initialized.
+       (gif_load): Initialize transparent_p to zero (Bug#8238).
+       Mark another local as initialized.
+       (my_png_error, my_error_exit): Mark with NO_RETURN.
+
+       * image.c (clear_image_cache): Now static.
+       (DIM, HAVE_STDLIB_H_1): Remove unused macros.
+       (xpm_load): Redo to avoid "discards qualifiers" gcc warning.
+       (x_edge_detection): Remove unnecessary cast that
+       gcc -Wbad-function-cast diagnoses.
+       (gif_load): Fix pointer signedness.
+       (clear_image_cache, xbm_read_bitmap_data, x_detect_edges):
+       (jpeg_load, gif_load): Rename locals to avoid shadowing.
+
+2011-03-11  Paul Eggert  <eggert@cs.ucla.edu>
+
        Improve quality of tests for time stamp overflow.
        For example, without this patch (encode-time 0 0 0 1 1
        1152921504606846976) returns the obviously-bogus value (-948597
index b1ea633..754f61e 100644 (file)
@@ -74,9 +74,11 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 #endif
 
 #ifndef HAVE_GTK3
+#ifdef USE_GTK_TOOLTIP
 #define gdk_window_get_screen(w) gdk_drawable_get_screen (w)
+#endif
 #define gdk_window_get_geometry(w, a, b, c, d) \
-  gdk_window_get_geometry (w, a, b, c, d, 0) 
+  gdk_window_get_geometry (w, a, b, c, d, 0)
 #define gdk_x11_window_lookup_for_display(d, w) \
   gdk_xid_table_lookup_for_display (d, w)
 #define GDK_KEY_g GDK_g
@@ -84,6 +86,13 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 
 #define XG_BIN_CHILD(x) gtk_bin_get_child (GTK_BIN (x))
 
+/* Get the current value of the range, truncated to an integer.  */
+static int
+int_gtk_range_get_value (GtkRange *range)
+{
+  return gtk_range_get_value (range);
+}
+
 \f
 /***********************************************************************
                       Display handling functions
@@ -258,7 +267,7 @@ xg_get_pixbuf_from_pixmap (FRAME_PTR f, Pixmap pix)
                    ~0, XYPixmap);
   if (!xim) return 0;
 
-  tmp_buf = gdk_pixbuf_new_from_data (xim->data,
+  tmp_buf = gdk_pixbuf_new_from_data ((guchar *) xim->data,
                                       GDK_COLORSPACE_RGB,
                                       FALSE,
                                       xim->bitmap_unit,
@@ -287,7 +296,7 @@ xg_get_pixbuf_from_pix_and_mask (FRAME_PTR f,
 
   width = gdk_pixbuf_get_width (icon_buf);
   height = gdk_pixbuf_get_height (icon_buf);
-  
+
   if (mask)
     {
       GdkPixbuf *mask_buf = xg_get_pixbuf_from_pixmap (f, mask);
@@ -393,7 +402,7 @@ xg_get_image_for_pixmap (FRAME_PTR f,
      Gtk+ assumes the pixmap is always there.  */
   icon_buf = xg_get_pixbuf_from_pix_and_mask (f, img->pixmap, img->mask);
 
-  if (icon_buf) 
+  if (icon_buf)
     {
       if (! old_widget)
         old_widget = GTK_IMAGE (gtk_image_new_from_pixbuf (icon_buf));
@@ -485,22 +494,22 @@ get_utf8_string (const char *str)
       gsize bytes_written;
       unsigned char *p = (unsigned char *)str;
       char *cp, *up;
-      GError *error = NULL;
+      GError *err = NULL;
 
       while (! (cp = g_locale_to_utf8 ((char *)p, -1, &bytes_read,
-                                       &bytes_written, &error))
-             && error->code == G_CONVERT_ERROR_ILLEGAL_SEQUENCE)
+                                       &bytes_written, &err))
+             && err->code == G_CONVERT_ERROR_ILLEGAL_SEQUENCE)
         {
           ++nr_bad;
           p += bytes_written+1;
-          g_error_free (error);
-          error = NULL;
+          g_error_free (err);
+          err = NULL;
         }
 
-      if (error)
+      if (err)
         {
-          g_error_free (error);
-          error = NULL;
+          g_error_free (err);
+          err = NULL;
         }
       if (cp) g_free (cp);
 
@@ -508,16 +517,16 @@ get_utf8_string (const char *str)
       p = (unsigned char *)str;
 
       while (! (cp = g_locale_to_utf8 ((char *)p, -1, &bytes_read,
-                                       &bytes_written, &error))
-             && error->code == G_CONVERT_ERROR_ILLEGAL_SEQUENCE)
+                                       &bytes_written, &err))
+             && err->code == G_CONVERT_ERROR_ILLEGAL_SEQUENCE)
         {
           strncpy (up, (char *)p, bytes_written);
           sprintf (up + bytes_written, "\\%03o", p[bytes_written]);
           up[bytes_written+4] = '\0';
           up += bytes_written+4;
           p += bytes_written+1;
-          g_error_free (error);
-          error = NULL;
+          g_error_free (err);
+          err = NULL;
         }
 
       if (cp)
@@ -525,10 +534,10 @@ get_utf8_string (const char *str)
           strcat (utf8_str, cp);
           g_free (cp);
         }
-      if (error)
+      if (err)
         {
-          g_error_free (error);
-          error = NULL;
+          g_error_free (err);
+          err = NULL;
         }
     }
   return utf8_str;
@@ -1188,7 +1197,9 @@ xg_free_frame_widgets (FRAME_PTR f)
 {
   if (FRAME_GTK_OUTER_WIDGET (f))
     {
+#ifdef USE_GTK_TOOLTIP
       struct x_output *x = f->output_data.x;
+#endif
       gtk_widget_destroy (FRAME_GTK_OUTER_WIDGET (f));
       FRAME_X_WINDOW (f) = 0; /* Set to avoid XDestroyWindow in xterm.c */
       FRAME_GTK_OUTER_WIDGET (f) = 0;
@@ -1406,8 +1417,6 @@ create_dialog (widget_value *wv,
   GtkDialog *wd = GTK_DIALOG (wdialog);
   GtkBox *cur_box = GTK_BOX (gtk_dialog_get_action_area (wd));
   widget_value *item;
-  GtkWidget *wvbox;
-  GtkWidget *whbox_up;
   GtkWidget *whbox_down;
 
   /* If the number of buttons is greater than 4, make two rows of buttons
@@ -1423,8 +1432,8 @@ create_dialog (widget_value *wv,
 
   if (make_two_rows)
     {
-      wvbox = gtk_vbox_new (TRUE, button_spacing);
-      whbox_up = gtk_hbox_new (FALSE, 0);
+      GtkWidget *wvbox = gtk_vbox_new (TRUE, button_spacing);
+      GtkWidget *whbox_up = gtk_hbox_new (FALSE, 0);
       whbox_down = gtk_hbox_new (FALSE, 0);
 
       gtk_box_pack_start (cur_box, wvbox, FALSE, FALSE, 0);
@@ -1693,7 +1702,7 @@ xg_get_file_with_chooser (FRAME_PTR f,
                          int mustmatch_p, int only_dir_p,
                          xg_get_file_func *func)
 {
-  char message[1024];
+  char msgbuf[1024];
 
   GtkWidget *filewin, *wtoggle, *wbox, *wmessage;
   GtkWindow *gwin = GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f));
@@ -1729,16 +1738,16 @@ xg_get_file_with_chooser (FRAME_PTR f,
 
   if (x_gtk_file_dialog_help_text)
     {
-      message[0] = '\0';
+      msgbuf[0] = '\0';
       /* Gtk+ 2.10 has the file name text entry box integrated in the dialog.
          Show the C-l help text only for versions < 2.10.  */
       if (gtk_check_version (2, 10, 0) && action != GTK_FILE_CHOOSER_ACTION_SAVE)
-        strcat (message, "\nType C-l to display a file name text entry box.\n");
-      strcat (message, "\nIf you don't like this file selector, use the "
+        strcat (msgbuf, "\nType C-l to display a file name text entry box.\n");
+      strcat (msgbuf, "\nIf you don't like this file selector, use the "
               "corresponding\nkey binding or customize "
               "use-file-dialog to turn it off.");
 
-      wmessage = gtk_label_new (message);
+      wmessage = gtk_label_new (msgbuf);
       gtk_widget_show (wmessage);
     }
 
@@ -3560,7 +3569,7 @@ xg_set_toolkit_scroll_bar_thumb (struct scroll_bar *bar,
           changed = 1;
         }
 
-      if (changed || (int) gtk_range_get_value (GTK_RANGE (wscroll)) != value)
+      if (changed || int_gtk_range_get_value (GTK_RANGE (wscroll)) != value)
       {
         BLOCK_INPUT;
 
@@ -3568,7 +3577,7 @@ xg_set_toolkit_scroll_bar_thumb (struct scroll_bar *bar,
            ignore_gtk_scrollbar to make the callback do nothing  */
         xg_ignore_gtk_scrollbar = 1;
 
-        if ((int) gtk_range_get_value (GTK_RANGE (wscroll)) != value)
+        if (int_gtk_range_get_value (GTK_RANGE (wscroll)) != value)
           gtk_range_set_value (GTK_RANGE (wscroll), (gdouble)value);
         else if (changed)
           gtk_adjustment_changed (adj);
@@ -3664,8 +3673,8 @@ xg_tool_bar_callback (GtkWidget *w, gpointer client_data)
 {
   /* The EMACS_INT cast avoids a warning. */
   int idx = (int) (EMACS_INT) client_data;
-  int mod = (int) (EMACS_INT) g_object_get_data (G_OBJECT (w),
-                                                 XG_TOOL_BAR_LAST_MODIFIER);
+  gpointer gmod = g_object_get_data (G_OBJECT (w), XG_TOOL_BAR_LAST_MODIFIER);
+  int mod = (int) (EMACS_INT) gmod;
 
   FRAME_PTR f = (FRAME_PTR) g_object_get_data (G_OBJECT (w), XG_FRAME_DATA);
   Lisp_Object key, frame;
@@ -4216,9 +4225,9 @@ xg_tool_item_stale_p (GtkWidget *wbutton, const char *stock_name,
     }
   else
     {
-      Pixmap old_img
-       = (Pixmap) g_object_get_data (G_OBJECT (wimage),
-                                     XG_TOOL_BAR_IMAGE_DATA);
+      gpointer gold_img = g_object_get_data (G_OBJECT (wimage),
+                                           XG_TOOL_BAR_IMAGE_DATA);
+      Pixmap old_img = (Pixmap) gold_img;
       if (old_img != img->pixmap)
        return 1;
     }
index c7820c3..7584f9b 100644 (file)
@@ -550,10 +550,6 @@ x_create_bitmap_mask (struct frame *f, int id)
                            Image types
  ***********************************************************************/
 
-/* Value is the number of elements of vector VECTOR.  */
-
-#define DIM(VECTOR)    (sizeof (VECTOR) / sizeof *(VECTOR))
-
 /* List of supported image types.  Use define_image_type to add new
    types.  Use lookup_image_type to find a type for a given symbol.  */
 
@@ -1141,7 +1137,7 @@ static RGB_PIXEL_COLOR
 four_corners_best (XImagePtr_or_DC ximg, int *corners,
                   unsigned long width, unsigned long height)
 {
-  RGB_PIXEL_COLOR corner_pixels[4], best;
+  RGB_PIXEL_COLOR corner_pixels[4], best IF_LINT (= 0);
   int i, best_count;
 
   if (corners && corners[BOT_CORNER] >= 0)
@@ -1493,7 +1489,7 @@ free_image_cache (struct frame *f)
    If image-cache-eviction-delay is non-nil, this frees images in the cache
    which weren't displayed for at least that many seconds.  */
 
-void
+static void
 clear_image_cache (struct frame *f, Lisp_Object filter)
 {
   struct image_cache *c = FRAME_IMAGE_CACHE (f);
@@ -1561,9 +1557,9 @@ clear_image_cache (struct frame *f, Lisp_Object filter)
 
          FOR_EACH_FRAME (tail, frame)
            {
-             struct frame *f = XFRAME (frame);
-             if (FRAME_IMAGE_CACHE (f) == c)
-               clear_current_matrices (f);
+             struct frame *fr = XFRAME (frame);
+             if (FRAME_IMAGE_CACHE (fr) == c)
+               clear_current_matrices (fr);
            }
 
          ++windows_or_buffers_changed;
@@ -2655,11 +2651,11 @@ xbm_read_bitmap_data (struct frame *f, unsigned char *contents, unsigned char *e
 
       if (LA1 == XBM_TK_NUMBER)
        {
-          char *p = strrchr (buffer, '_');
-         p = p ? p + 1 : buffer;
-          if (strcmp (p, "width") == 0)
+         char *q = strrchr (buffer, '_');
+         q = q ? q + 1 : buffer;
+         if (strcmp (q, "width") == 0)
            *width = value;
-          else if (strcmp (p, "height") == 0)
+         else if (strcmp (q, "height") == 0)
            *height = value;
        }
       expect (XBM_TK_NUMBER);
@@ -3429,11 +3425,12 @@ xpm_load (struct frame *f, struct image *img)
        {
          Lisp_Object name;
          Lisp_Object color;
+         char *empty_string = (char *) "";
 
          if (!CONSP (XCAR (tail)))
            {
-             xpm_syms[i].name = "";
-             xpm_syms[i].value = "";
+             xpm_syms[i].name = empty_string;
+             xpm_syms[i].value = empty_string;
              continue;
            }
          name = XCAR (XCAR (tail));
@@ -3444,14 +3441,14 @@ xpm_load (struct frame *f, struct image *img)
              strcpy (xpm_syms[i].name, SSDATA (name));
            }
          else
-           xpm_syms[i].name = "";
+           xpm_syms[i].name = empty_string;
          if (STRINGP (color))
            {
              xpm_syms[i].value = (char *) alloca (SCHARS (color) + 1);
              strcpy (xpm_syms[i].value, SSDATA (color));
            }
          else
-           xpm_syms[i].value = "";
+           xpm_syms[i].value = empty_string;
        }
     }
 
@@ -4607,14 +4604,14 @@ x_detect_edges (struct frame *f, struct image *img, int *matrix, int color_adjus
 
       for (x = 1; x < img->width - 1; ++x, ++p)
        {
-         int r, g, b, y1, x1;
+         int r, g, b, yy, xx;
 
          r = g = b = i = 0;
-         for (y1 = y - 1; y1 < y + 2; ++y1)
-           for (x1 = x - 1; x1 < x + 2; ++x1, ++i)
+         for (yy = y - 1; yy < y + 2; ++yy)
+           for (xx = x - 1; xx < x + 2; ++xx, ++i)
              if (matrix[i])
                {
-                 XColor *t = COLOR (colors, x1, y1);
+                 XColor *t = COLOR (colors, xx, yy);
                  r += matrix[i] * t->red;
                  g += matrix[i] * t->green;
                  b += matrix[i] * t->blue;
@@ -4690,7 +4687,7 @@ x_edge_detection (struct frame *f, struct image *img, Lisp_Object matrix,
     color_adjust = make_number (0xffff / 2);
 
   if (i == 9 && NUMBERP (color_adjust))
-    x_detect_edges (f, img, trans, (int) XFLOATINT (color_adjust));
+    x_detect_edges (f, img, trans, XFLOATINT (color_adjust));
 }
 
 
@@ -5533,6 +5530,7 @@ init_png_functions (Lisp_Object libraries)
 /* Error and warning handlers installed when the PNG library
    is initialized.  */
 
+static void my_png_error (png_struct *, const char *) NO_RETURN;
 static void
 my_png_error (png_struct *png_ptr, const char *msg)
 {
@@ -6032,7 +6030,6 @@ jpeg_image_p (Lisp_Object object)
 /* Work around a warning about HAVE_STDLIB_H being redefined in
    jconfig.h.  */
 #ifdef HAVE_STDLIB_H
-#define HAVE_STDLIB_H_1
 #undef HAVE_STDLIB_H
 #endif /* HAVE_STLIB_H */
 
@@ -6108,6 +6105,7 @@ struct my_jpeg_error_mgr
 };
 
 
+static void my_error_exit (j_common_ptr) NO_RETURN;
 static void
 my_error_exit (j_common_ptr cinfo)
 {
@@ -6368,10 +6366,10 @@ jpeg_load (struct frame *f, struct image *img)
       if (rc == 1)
        {
          /* Called from my_error_exit.  Display a JPEG error.  */
-         char buffer[JMSG_LENGTH_MAX];
-         cinfo.err->format_message ((j_common_ptr) &cinfo, buffer);
+         char buf[JMSG_LENGTH_MAX];
+         cinfo.err->format_message ((j_common_ptr) &cinfo, buf);
          image_error ("Error reading JPEG image `%s': %s", img->spec,
-                      build_string (buffer));
+                      build_string (buf));
        }
 
       /* Close the input file and destroy the JPEG object.  */
@@ -7107,7 +7105,7 @@ gif_load (struct frame *f, struct image *img)
   Lisp_Object file, specified_file;
   Lisp_Object specified_data;
   int rc, width, height, x, y, i;
-  boolean transparent_p;
+  boolean transparent_p = 0;
   XImagePtr ximg;
   ColorMapObject *gif_color_map;
   unsigned long pixel_colors[256];
@@ -7116,7 +7114,7 @@ gif_load (struct frame *f, struct image *img)
   int ino, image_height, image_width;
   gif_memory_source memsrc;
   unsigned char *raster;
-  unsigned int transparency_color_index;
+  unsigned int transparency_color_index IF_LINT (= 0);
 
   specified_file = image_spec_value (img->spec, QCfile, NULL);
   specified_data = image_spec_value (img->spec, QCdata, NULL);
@@ -7131,7 +7129,7 @@ gif_load (struct frame *f, struct image *img)
        }
 
       /* Open the GIF file.  */
-      gif = fn_DGifOpenFileName (SDATA (file));
+      gif = fn_DGifOpenFileName (SSDATA (file));
       if (gif == NULL)
        {
          image_error ("Cannot open `%s'", file, Qnil);
@@ -7304,9 +7302,9 @@ gif_load (struct frame *f, struct image *img)
 
          for (x = 0; x < image_width; x++)
            {
-             int i = raster[(y * image_width) + x];
+             int c = raster[(y * image_width) + x];
              XPutPixel (ximg, x + img->corners[LEFT_CORNER],
-                        row + img->corners[TOP_CORNER], pixel_colors[i]);
+                        row + img->corners[TOP_CORNER], pixel_colors[c]);
            }
 
          row += interlace_increment[pass];
@@ -7317,9 +7315,9 @@ gif_load (struct frame *f, struct image *img)
       for (y = 0; y < image_height; ++y)
        for (x = 0; x < image_width; ++x)
          {
-           int i = raster[y * image_width + x];
+           int c = raster[y * image_width + x];
            XPutPixel (ximg, x + img->corners[LEFT_CORNER],
-                      y + img->corners[TOP_CORNER], pixel_colors[i]);
+                      y + img->corners[TOP_CORNER], pixel_colors[c]);
          }
     }
 
index 359a8fb..96d763f 100644 (file)
@@ -38,7 +38,7 @@ xg_select (int max_fds, SELECT_TYPE *rfds, SELECT_TYPE *wfds, SELECT_TYPE *efds,
   GMainContext *context = g_main_context_default ();
   int have_wfds = wfds != NULL;
   int n_gfds = 0, our_tmo = 0, retval = 0, our_fds = 0;
-  int prio, i, nfds, tmo_in_millisec;
+  int i, nfds, tmo_in_millisec;
 
   if (rfds) memcpy (&all_rfds, rfds, sizeof (all_rfds));
   else FD_ZERO (&all_rfds);
@@ -49,9 +49,9 @@ xg_select (int max_fds, SELECT_TYPE *rfds, SELECT_TYPE *wfds, SELECT_TYPE *efds,
   g_main_context_pending (context);
 
   do {
-    if (n_gfds > gfds_size) 
+    if (n_gfds > gfds_size)
       {
-        while (n_gfds > gfds_size) 
+        while (n_gfds > gfds_size)
           gfds_size *= 2;
         xfree (gfds);
         gfds = xmalloc (sizeof (*gfds) * gfds_size);
@@ -64,7 +64,7 @@ xg_select (int max_fds, SELECT_TYPE *rfds, SELECT_TYPE *wfds, SELECT_TYPE *efds,
                                    gfds_size);
   } while (n_gfds > gfds_size);
 
-  for (i = 0; i < n_gfds; ++i) 
+  for (i = 0; i < n_gfds; ++i)
     {
       if (gfds[i].events & G_IO_IN)
         {
@@ -87,7 +87,7 @@ xg_select (int max_fds, SELECT_TYPE *rfds, SELECT_TYPE *wfds, SELECT_TYPE *efds,
       else
         {
           EMACS_TIME difference;
-          
+
           EMACS_SUB_TIME (difference, tmo, *timeout);
           if (EMACS_TIME_NEG_P (difference)) our_tmo = 1;
         }
@@ -100,7 +100,7 @@ xg_select (int max_fds, SELECT_TYPE *rfds, SELECT_TYPE *wfds, SELECT_TYPE *efds,
 
   if (nfds < 0)
     retval = nfds;
-  else if (nfds > 0) 
+  else if (nfds > 0)
     {
       for (i = 0; i < max_fds+1; ++i)
         {
@@ -127,7 +127,7 @@ xg_select (int max_fds, SELECT_TYPE *rfds, SELECT_TYPE *wfds, SELECT_TYPE *efds,
 
   if (our_fds > 0 || (nfds == 0 && our_tmo))
     {
-      
+
       /* If Gtk+ is in use eventually gtk_main_iteration will be called,
          unless retval is zero.  */
 #ifdef USE_GTK
@@ -137,7 +137,7 @@ xg_select (int max_fds, SELECT_TYPE *rfds, SELECT_TYPE *wfds, SELECT_TYPE *efds,
           g_main_context_dispatch (context);
 
       /* To not have to recalculate timeout, return like this.  */
-      if (retval == 0) 
+      if (retval == 0)
         {
           retval = -1;
           errno = EINTR;
@@ -156,4 +156,3 @@ xgselect_initialize (void)
   gfds = xmalloc (sizeof (*gfds)*gfds_size);
 #endif /* defined (USE_GTK) || defined (HAVE_GCONF) */
 }
-