emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 62c2afe8410 05/11: Pacify GCC 14 -Wnull-dereference


From: Paul Eggert
Subject: master 62c2afe8410 05/11: Pacify GCC 14 -Wnull-dereference
Date: Tue, 30 Apr 2024 04:26:37 -0400 (EDT)

branch: master
commit 62c2afe84107de96b850c1da7a2b80bcab6e588a
Author: Paul Eggert <eggert@cs.ucla.edu>
Commit: Paul Eggert <eggert@cs.ucla.edu>

    Pacify GCC 14 -Wnull-dereference
    
    * src/xterm.c (x_dpyinfo): New function, which acts like
    x_display_info_for_display except it always returns nonnull.
    This simplifies callers and pacifies GCC 14.  All callers changed.
---
 src/xfaces.c |  2 +-
 src/xfns.c   | 10 ++--------
 src/xmenu.c  |  2 +-
 src/xterm.c  | 62 +++++++++++++++++++++++++++++-------------------------------
 src/xterm.h  |  2 ++
 5 files changed, 36 insertions(+), 42 deletions(-)

diff --git a/src/xfaces.c b/src/xfaces.c
index 56d067ade5b..d5079491258 100644
--- a/src/xfaces.c
+++ b/src/xfaces.c
@@ -504,7 +504,7 @@ void
 x_free_dpy_colors (Display *dpy, Screen *screen, Colormap cmap,
                   unsigned long *pixels, int npixels)
 {
-  struct x_display_info *dpyinfo = x_display_info_for_display (dpy);
+  struct x_display_info *dpyinfo = x_dpyinfo (dpy);
 
   /* If display has an immutable color map, freeing colors is not
      necessary and some servers don't allow it.  So don't do it.  */
diff --git a/src/xfns.c b/src/xfns.c
index 67db461a379..c48fa24b6be 100644
--- a/src/xfns.c
+++ b/src/xfns.c
@@ -6547,10 +6547,7 @@ void
 xlw_monitor_dimensions_at_pos (Display *dpy, Screen *screen, int src_x,
                               int src_y, int *x, int *y, int *width, int 
*height)
 {
-  struct x_display_info *dpyinfo = x_display_info_for_display (dpy);
-
-  if (!dpyinfo)
-    emacs_abort ();
+  struct x_display_info *dpyinfo = x_dpyinfo (dpy);
 
   block_input ();
   xlw_monitor_dimensions_at_pos_1 (dpyinfo, screen, src_x, src_y,
@@ -10214,10 +10211,7 @@ XkbFreeNames (XkbDescPtr xkb, unsigned int which, Bool 
free_map)
 int
 XDisplayCells (Display *dpy, int screen_number)
 {
-  struct x_display_info *dpyinfo = x_display_info_for_display (dpy);
-
-  if (!dpyinfo)
-    emacs_abort ();
+  struct x_display_info *dpyinfo = x_dpyinfo (dpy);
 
   /* Not strictly correct, since the display could be using a
      non-default visual, but it satisfies the callers we need to care
diff --git a/src/xmenu.c b/src/xmenu.c
index ef1eeb5925f..8682e67dad4 100644
--- a/src/xmenu.c
+++ b/src/xmenu.c
@@ -236,7 +236,7 @@ x_menu_translate_generic_event (XEvent *event)
   XEvent copy;
   XIDeviceEvent *xev;
 
-  dpyinfo = x_display_info_for_display (event->xgeneric.display);
+  dpyinfo = x_dpyinfo (event->xgeneric.display);
 
   if (event->xgeneric.extension == dpyinfo->xi2_opcode)
     {
diff --git a/src/xterm.c b/src/xterm.c
index 93d347a77ef..c6cc4a9cae6 100644
--- a/src/xterm.c
+++ b/src/xterm.c
@@ -2933,7 +2933,6 @@ x_dnd_free_toplevels (bool display_alive)
   unsigned long *prev_masks UNINIT;
   specpdl_ref count;
   Display *dpy UNINIT;
-  struct x_display_info *dpyinfo;
 
   if (!x_dnd_toplevels)
     /* Probably called inside an IO error handler.  */
@@ -2995,25 +2994,21 @@ x_dnd_free_toplevels (bool display_alive)
   record_unwind_protect_ptr (xfree, destroy_windows);
   record_unwind_protect_ptr (xfree, prev_masks);
 
-  if (display_alive)
+  if (display_alive && n_windows)
     {
-      dpyinfo = x_display_info_for_display (dpy);
+      struct x_display_info *dpyinfo = x_dpyinfo (dpy);
 
-      if (n_windows)
-       {
-         eassume (dpyinfo);
-         x_ignore_errors_for_next_request (dpyinfo, 0);
+      x_ignore_errors_for_next_request (dpyinfo, 0);
 
-         for (i = 0; i < n_windows; ++i)
-           {
-             XSelectInput (dpy, destroy_windows[i], prev_masks[i]);
+      for (i = 0; i < n_windows; ++i)
+       {
+         XSelectInput (dpy, destroy_windows[i], prev_masks[i]);
 #ifdef HAVE_XSHAPE
-             XShapeSelectInput (dpy, destroy_windows[i], None);
+         XShapeSelectInput (dpy, destroy_windows[i], None);
 #endif
-           }
-
-         x_stop_ignoring_errors (dpyinfo);
        }
+
+      x_stop_ignoring_errors (dpyinfo);
     }
 
   unbind_to (count, Qnil);
@@ -6881,7 +6876,20 @@ x_draw_horizontal_wave (struct frame *f, GC gc, int x, 
int y,
 #endif
 
 
-/* Return the struct x_display_info corresponding to DPY.  */
+/* Return the struct x_display_info corresponding to DPY,
+   when it is guaranteed that one will correspond.  */
+
+struct x_display_info *
+x_dpyinfo (Display *dpy)
+{
+  for (struct x_display_info *dpyinfo = x_display_list; ;
+       dpyinfo = dpyinfo->next)
+    if (dpyinfo->display == dpy)
+      return dpyinfo;
+}
+
+/* Return the struct x_display_info corresponding to DPY,
+   or a null pointer if none corresponds.  */
 
 struct x_display_info *
 x_display_info_for_display (Display *dpy)
@@ -8895,7 +8903,7 @@ x_frame_of_widget (Widget widget)
   Lisp_Object tail, frame;
   struct frame *f;
 
-  dpyinfo = x_display_info_for_display (XtDisplay (widget));
+  dpyinfo = x_dpyinfo (XtDisplay (widget));
 
   /* Find the top-level shell of the widget.  Note that this function
      can be called when the widget is not yet realized, so XtWindow
@@ -9089,8 +9097,7 @@ cvt_pixel_dtor (XtAppContext app, XrmValuePtr to, 
XtPointer closure, XrmValuePtr
 static const XColor *
 x_color_cells (Display *dpy, int *ncells)
 {
-  struct x_display_info *dpyinfo = x_display_info_for_display (dpy);
-  eassume (dpyinfo);
+  struct x_display_info *dpyinfo = x_dpyinfo (dpy);
 
   if (dpyinfo->color_cells == NULL)
     {
@@ -9365,16 +9372,13 @@ x_parse_color (struct frame *f, const char *color_name,
 static bool
 x_alloc_nearest_color_1 (Display *dpy, Colormap cmap, XColor *color)
 {
-  struct x_display_info *dpyinfo = x_display_info_for_display (dpy);
-  bool rc;
-
-  eassume (dpyinfo);
-  rc = XAllocColor (dpy, cmap, color) != 0;
+  struct x_display_info *dpyinfo = x_dpyinfo (dpy);
+  bool rc = XAllocColor (dpy, cmap, color) != 0;
 
   if (dpyinfo->visual_info.class == DirectColor)
     return rc;
 
-  if (rc == 0)
+  if (!rc)
     {
       /* If we got to this point, the colormap is full, so we're going
         to try and get the next closest color.  The algorithm used is
@@ -9477,8 +9481,7 @@ x_alloc_nearest_color_1 (Display *dpy, Colormap cmap, 
XColor *color)
       /* If allocation succeeded, and the allocated pixel color is not
          equal to a cached pixel color recorded earlier, there was a
          change in the colormap, so clear the color cache.  */
-      struct x_display_info *dpyinfo = x_display_info_for_display (dpy);
-      eassume (dpyinfo);
+      struct x_display_info *dpyinfo = x_dpyinfo (dpy);
 
       if (dpyinfo->color_cells)
        {
@@ -14607,12 +14610,7 @@ x_query_pointer (Display *dpy, Window w, Window 
*root_return,
                 int *root_y_return, int *win_x_return,
                 int *win_y_return, unsigned int *mask_return)
 {
-  struct x_display_info *dpyinfo;
-
-  dpyinfo = x_display_info_for_display (dpy);
-
-  if (!dpyinfo)
-    emacs_abort ();
+  struct x_display_info *dpyinfo = x_dpyinfo (dpy);
 
 #ifdef HAVE_XINPUT2
   return x_query_pointer_1 (dpyinfo, dpyinfo->client_pointer_device,
diff --git a/src/xterm.h b/src/xterm.h
index 2c00b1e7bec..437ef281b0c 100644
--- a/src/xterm.h
+++ b/src/xterm.h
@@ -993,6 +993,8 @@ extern int popup_activated_flag;
 /* This is a chain of structures for all the X displays currently in use.  */
 extern struct x_display_info *x_display_list;
 
+extern struct x_display_info *x_dpyinfo (Display *)
+  ATTRIBUTE_RETURNS_NONNULL;
 extern struct x_display_info *x_display_info_for_display (Display *);
 extern struct frame *x_top_window_to_frame (struct x_display_info *, int);
 extern struct x_display_info *x_term_init (Lisp_Object, char *, char *);



reply via email to

[Prev in Thread] Current Thread [Next in Thread]